home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume10 / asm.8051 < prev    next >
Encoding:
Text File  |  1990-02-13  |  82.8 KB  |  3,709 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v10i060: An 8031/8051 Assembler
  3. From: stauffer@cpsc.ucalgary.ca (Kenneth Stauffer)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 10, Issue 60
  7. Submitted-by: stauffer@cpsc.ucalgary.ca (Kenneth Stauffer)
  8. Archive-name: asm.8051
  9.  
  10. This is an 8031/8051 Assembler, which generates
  11. many different output formats including S-records.
  12.  
  13. Ken Stauffer.
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of shell archive."
  22. # Contents:  README as31.h as31.y as31.man emitter.c lexer.c main.c
  23. #   makefile symbol.c new.asm
  24. # Wrapped by stauffer@cpsc.UCalgary.CA on Tue Jan 30 18:35:17 1990
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'README' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'README'\"
  28. else
  29. echo shar: Extracting \"'README'\" \(1528 characters\)
  30. sed "s/^X//" >'README' <<'END_OF_FILE'
  31. X
  32. X
  33. X    as31 - An 8031/8051 assembler.
  34. X
  35. X        Written by:
  36. X    K e n    S t a u f f e r
  37. X
  38. X
  39. Xas31, is an 8031/8051 assembler. The program consists of the
  40. Xfollowing files:
  41. X
  42. X    makefile    - Makefile.
  43. X    as31.h        - Package header file.
  44. X    as31.y        - Parser / code generator.
  45. X    lexer.c        - Scanner.
  46. X    symbol.c    - Symbol table / opcode table.
  47. X    emitter.c    - Object code generation routines.
  48. X    main.c        - Command line / calls yyparse().
  49. X
  50. X    as31.man    - Assembler manual.
  51. X
  52. X    new.asm        - Sample 8031 code. This is a working
  53. X              debugger written by Theo Deraadt.
  54. X
  55. XOVERVIEW OF AS31:
  56. X    as31 is a full featured assembler but it does lack
  57. X    facilities for linking several modules together.
  58. X    as31 can be configured to produced a wide variety of
  59. X    object output formats.
  60. X    One of the supported output formats is S-records.
  61. X        (Written by: Theo Deraadt)
  62. X
  63. X    Standard assembler syntax is accepted.
  64. X
  65. XMAKING AS31:
  66. X    On most unix systems, running make should be sufficient
  67. X    to produce a working assembler.
  68. X
  69. X    Also typing:
  70. X
  71. X        % make man
  72. X
  73. X    Will produces a text file from as31.man (called as31.cat).
  74. X    This is the users manual.
  75. X
  76. X    This package does work on the following systems:
  77. X        SUN 3 / SUN 4 (SunOS 4.0), Tandy 6000 (Xenix)
  78. X
  79. X    Non-unix systems may require some porting for the FILE I/O
  80. X    stuff but most reasonable implementations of stdio.h
  81. X    should work.
  82. X
  83. XSOURCE CODE:
  84. X    This code is public domain.
  85. X
  86. XREPORTING BUGS:
  87. X    If any bugs are detected in this program, I would
  88. X    like to know about them so that I could fix them. I can
  89. X    be reached via E-mail at:
  90. X
  91. X        stauffer@cpsc.ucalgary.ca
  92. X
  93. XJanuary 26, 1990
  94. X
  95. END_OF_FILE
  96. if test 1528 -ne `wc -c <'README'`; then
  97.     echo shar: \"'README'\" unpacked with wrong size!
  98. fi
  99. # end of 'README'
  100. fi
  101. if test -f 'as31.h' -a "${1}" != "-c" ; then 
  102.   echo shar: Will not clobber existing file \"'as31.h'\"
  103. else
  104. echo shar: Extracting \"'as31.h'\" \(3549 characters\)
  105. sed "s/^X//" >'as31.h' <<'END_OF_FILE'
  106. X/* ----------------------------------------------------------------------
  107. X * FILE: as31.h
  108. X * PACKAGE: as31 - 8031/8051 Assembler.
  109. X *
  110. X * DESCRIPTION:
  111. X *    The sole header file for the 8031/8051 assembler package.
  112. X *    It defines several structures used by the yacc stack.
  113. X *    It defines several macros for testing the bitsize of numeric
  114. X *    quantities.
  115. X *
  116. X *    Some macros to extract information from the mode structure.
  117. X *
  118. X * REVISION HISTORY:
  119. X *    Jan. 19, 1990 - Created. (Ken Stauffer)
  120. X *
  121. X * AUTHOR:
  122. X *    All code in this file written by Ken Stauffer (University of Calgary).
  123. X *    January, 1990.
  124. X *
  125. X */
  126. X
  127. X/* ----------------------------------------------------------------------
  128. X * user / keyword symbol structures:
  129. X */
  130. X
  131. Xstruct opcode {
  132. X    char *name;
  133. X    int type;
  134. X    unsigned char *bytes;
  135. X};
  136. X
  137. Xstruct symbol {
  138. X    char *name;
  139. X    int type;
  140. X    long value;
  141. X    struct symbol *next;
  142. X};
  143. X
  144. X#define UNDEF    0
  145. X#define LABEL    1
  146. X
  147. X/* ----------------------------------------------------------------------
  148. X * addressing mode stuff:
  149. X */
  150. X
  151. Xstruct mode {
  152. X    unsigned char mode;        /* value to index with */
  153. X    unsigned char size;        /* # of bytes used */
  154. X    unsigned char orval;        /* value OR'd to obcode */
  155. X    unsigned char byte1;        /* extra byte 1 */
  156. X    unsigned char byte2;        /* extra byte 2 */
  157. X};
  158. X
  159. X#define set_md(m,a)    ((m).mode=(a))
  160. X#define set_sz(m,a)    ((m).size=(a))
  161. X#define set_ov(m,a)    ((m).orval=(a))
  162. X#define set_b1(m,a)    ((m).byte1=(a))
  163. X#define set_b2(m,a)    ((m).byte2=(a))
  164. X
  165. X#define get_md(m)    ((m).mode)
  166. X#define get_sz(m)    ((m).size)
  167. X#define get_ov(m)    ((m).orval)
  168. X#define get_b1(m)    ((m).byte1)
  169. X#define get_b2(m)    ((m).byte2)
  170. X
  171. X/* ----------------------------------------------------------------------
  172. X * yacc stack stuff:
  173. X */
  174. X
  175. Xstruct value {
  176. X    long v;
  177. X    unsigned char d;        /* expression defined flag */
  178. X};
  179. X
  180. Xunion ystack {
  181. X    long value;
  182. X    struct value val;
  183. X    struct opcode *op;
  184. X    struct symbol *sym;
  185. X    struct mode mode;
  186. X    char *str;
  187. X};
  188. X
  189. X/* ----------------------------------------------------------------------
  190. X * IS_BIT_MAPPED_RAM:
  191. X *    True is the byte 'a' is the byte address of a bit mapped
  192. X *    RAM location.
  193. X */
  194. X#define isbmram(a)    (((a)&0xf0)==0x20)
  195. X
  196. X/* ----------------------------------------------------------------------
  197. X * IS_BIT_MAPPED_SFR:
  198. X *    True is the byte 'a' is the byte address of a bit mapped
  199. X *    SPECIAL FUCTION REGISTER.
  200. X */
  201. X#define isbmsfr(a)    (((a)&0x80) && !((a) & 0x07))
  202. X
  203. X/* ----------------------------------------------------------------------
  204. X * isbit8, ...
  205. X *    Macros to check the sizes of values and to convert
  206. X *    a value to a certain, size.
  207. X *
  208. X */
  209. X#define size8        (~0x00ff)
  210. X#define size11        (~0x07ff)
  211. X#define size13        (~0x1fff)
  212. X#define size16        (~0xffff)
  213. X
  214. X#define size10        (~0x03ff)
  215. X#define size12        (~0x0fff)
  216. X#define size15        (~0x7fff)
  217. X
  218. X#define isbit8(v)    ( !( ((v)>=0) ? (v)&size8 : -(v)>=128) )
  219. X#define isbit11(v)    ( !( ((v)>=0) ? (v)&size11 : (-(v))&size10 ) )
  220. X#define isbit13(v)    ( !( ((v)>=0) ? (v)&size13 : (-(v))&size12 ) )
  221. X#define isbit16(v)    ( !( ((v)>=0) ? (v)&size16 : (-(v))&size15 ) )
  222. X
  223. X/* ----------------------------------------------------------------------
  224. X * Size of user hash table.
  225. X */
  226. X#define HASHTABSIZE        1000
  227. X
  228. X/* ----------------------------------------------------------------------
  229. X * Macros to nicely test which pass we are in.
  230. X */
  231. X#define pass1            (!pass)
  232. X#define pass2            (pass)
  233. X
  234. X/* -------- TOKENS ------------------------------------------------------
  235. X *
  236. X * This includes the header file generated by yacc -d.
  237. X * NOPE is defined inside of as31.y, which does not
  238. X * need to re-include the tokens twice, thus NOPE prevents this.
  239. X *
  240. X */
  241. X#ifdef NOPE
  242. X#else
  243. X#include "y.tab.h"
  244. X#endif
  245. X
  246. END_OF_FILE
  247. if test 3549 -ne `wc -c <'as31.h'`; then
  248.     echo shar: \"'as31.h'\" unpacked with wrong size!
  249. fi
  250. # end of 'as31.h'
  251. fi
  252. if test -f 'as31.y' -a "${1}" != "-c" ; then 
  253.   echo shar: Will not clobber existing file \"'as31.y'\"
  254. else
  255. echo shar: Extracting \"'as31.y'\" \(22290 characters\)
  256. sed "s/^X//" >'as31.y' <<'END_OF_FILE'
  257. X/* ----------------------------------------------------------------------
  258. X * FILE: as31.y
  259. X * PACKAGE: as31 - 8031/8051 Assembler.
  260. X *
  261. X * DESCRIPTION:
  262. X *    This file contains the yacc parser for the assembler.
  263. X *    Related to this are the following:
  264. X *        error(), warning(), yyerror()
  265. X *        genbyte(), genword(), genstr(), makeop()
  266. X *
  267. X *
  268. X * REVISION HISTORY:
  269. X *    Jan. 19, 1990 - Created. (Ken Stauffer)
  270. X *
  271. X * AUTHOR:
  272. X *    All code in this file written by Ken Stauffer (University of Calgary).
  273. X *    January 1990.
  274. X *
  275. X */
  276. X
  277. X%{
  278. X
  279. X#include <setjmp.h>
  280. X#include <stdio.h>
  281. X#define NOPE
  282. X#include "as31.h"
  283. X#undef NOPE
  284. X
  285. X#define YYSTYPE union ystack
  286. X
  287. Xextern int lineno;
  288. Xextern int dashl;
  289. Xextern char *asmfile;
  290. Xextern jmp_buf main_env;
  291. Xextern FILE *listing;
  292. X
  293. Xint pass,fatal;
  294. Xunsigned long lc;
  295. X
  296. Xstatic unsigned char bytebuf[1024];        /* used by dumplist() */
  297. Xstatic int bytecount;
  298. X
  299. X/* ------------------------ G R A M M E R ----------------------------- */
  300. X
  301. X%}
  302. X
  303. X%token STRING
  304. X%token D_ORG
  305. X%token D_BYTE
  306. X%token D_WORD
  307. X%token D_SKIP
  308. X%token D_EQU
  309. X%token D_FLAG
  310. X%token D_END
  311. X%token ACALL
  312. X%token ADD
  313. X%token ADDC
  314. X%token AJMP
  315. X%token ANL
  316. X%token CJNE
  317. X%token CLR
  318. X%token CPL
  319. X%token DA
  320. X%token DEC
  321. X%token DIV
  322. X%token DJNZ
  323. X%token INC
  324. X%token JB
  325. X%token JBC
  326. X%token JC
  327. X%token JMP
  328. X%token JNB
  329. X%token JNC
  330. X%token JNZ
  331. X%token JZ
  332. X%token LCALL
  333. X%token LJMP
  334. X%token MOV
  335. X%token MOVC
  336. X%token MOVX
  337. X%token NOP
  338. X%token MUL
  339. X%token ORL
  340. X%token POP
  341. X%token PUSH
  342. X%token RET
  343. X%token RETI
  344. X%token RL
  345. X%token RLC
  346. X%token RR
  347. X%token RRC
  348. X%token SETB
  349. X%token SJMP
  350. X%token SUBB
  351. X%token SWAP
  352. X%token XCH
  353. X%token XCHD
  354. X%token XRL
  355. X%token AB
  356. X%token A
  357. X%token C
  358. X%token PC
  359. X%token DPTR
  360. X%token BITPOS
  361. X%token R0
  362. X%token R1
  363. X%token R2
  364. X%token R3
  365. X%token R4
  366. X%token R5
  367. X%token R6
  368. X%token R7
  369. X%token VALUE
  370. X%token SYMBOL
  371. X
  372. X%left '+' '-'
  373. X%left '*' '/' '%'
  374. X%left '|' '&'
  375. X
  376. X%start program
  377. X
  378. X%%
  379. Xprogram        :    linelist
  380. X{
  381. X}
  382. X        ;
  383. X
  384. Xlinelist    : linelist line
  385. X        | line
  386. X        ;
  387. X
  388. Xline        : undefsym ':' linerest
  389. X{
  390. X    if( pass1 ) {
  391. X        $1.sym->type = LABEL;
  392. X        $1.sym->value = lc;
  393. X    }
  394. X    inclc($3.value);
  395. X    bytecount = 0;
  396. X}
  397. X        | linerest        { inclc($1.value); bytecount = 0; }
  398. X        ;
  399. X
  400. Xlinerest    : directive '\n'    {
  401. X                        $$.value = $1.value;
  402. X                        if( dashl && pass2 )
  403. X                            dumplist($2.str,1);
  404. X                    }
  405. X        | instr '\n'        {
  406. X                        $$.value = $1.value;
  407. X                        if( dashl && pass2 )
  408. X                            dumplist($2.str,1);
  409. X
  410. X                    }
  411. X        | '\n'            {
  412. X                        $$.value = 0;
  413. X                        if( dashl && pass2 )
  414. X                            dumplist($1.str,0);
  415. X                    }
  416. X        ;
  417. X
  418. X
  419. X
  420. X
  421. X
  422. X/* --------------------
  423. X * DIRECTIVES:
  424. X *
  425. X */
  426. X
  427. Xdirective    : '.' D_ORG defexpr
  428. X{
  429. X    lc = $3.val.v;
  430. X    if( pass2 ) emitaddr(lc);
  431. X    bytecount = 0;
  432. X    $$.value = 0;
  433. X}
  434. X        | '.' D_BYTE blist    { $$.value = $3.value; }
  435. X        | '.' D_WORD wlist    { $$.value = $3.value; }
  436. X        | '.' D_SKIP defexpr    { $$.value = $3.val.v;
  437. X                      if( pass2 )
  438. X                        emitaddr(lc+$$.value); }
  439. X        | '.' D_EQU undefsym ',' expr
  440. X{
  441. X    if( $5.val.d == 0 )
  442. X        error("Expression is undefined in pass 1");
  443. X    $3.sym->type = LABEL;
  444. X    $3.sym->value = $5.val.v;
  445. X    $$.value = 0;
  446. X}
  447. X    
  448. X        | '.' D_FLAG SYMBOL ',' flag
  449. X{
  450. X    $3.sym->type = LABEL;
  451. X    $3.sym->value = $5.value;
  452. X    $$.value = 0;
  453. X}
  454. X        | '.' D_END            { $$.value = 0; }
  455. X        ;
  456. X
  457. Xdefexpr        : expr
  458. X{
  459. X        if( $1.val.d == 0 )
  460. X            error("Expression is undefined in pass 1");
  461. X        if( !(isbit16($1.val.v)) )
  462. X            error("Value greater than 16-bits");
  463. X        $$.value = $1.val.v;
  464. X}
  465. X        ;
  466. X
  467. Xflag        : flagv BITPOS
  468. X{
  469. X    if( !isbit8($1.value) )
  470. X        warning("Bit address exceeds 8-bits");
  471. X    if( isbmram($1.value) )
  472. X        $$.value = ($1.value-0x20)*8+ $2.value;
  473. X    else if( isbmsfr($1.value) )
  474. X        $$.value = $1.value + $2.value;
  475. X    else
  476. X        warning("Invalid bit addressable RAM location");
  477. X}
  478. X        ;
  479. X
  480. Xflagv        : SYMBOL
  481. X{
  482. X    if( $1.sym->type == UNDEF )
  483. X        error("Symbol %s must be defined in pass 1",$1.sym->name);
  484. X    $$.value = $1.sym->value;
  485. X}
  486. X        | VALUE            { $$.value = $1.value; }
  487. X        ;
  488. X
  489. X
  490. Xundefsym    : SYMBOL
  491. X{
  492. X    if( $1.sym->type != UNDEF && pass1)
  493. X        error("Attempt to redefine symbol: %s",$1.sym->name);
  494. X    $$.sym = $1.sym;
  495. X}
  496. X        ;
  497. X
  498. Xblist        : blist ',' data8
  499. X{
  500. X    if( pass2 ) genbyte($3.value);
  501. X    $$.value = $1.value + 1;
  502. X}
  503. X        | blist ',' STRING
  504. X{
  505. X    if( pass1 )
  506. X        $$.value = $1.value + $3.value;
  507. X    else {
  508. X        $$.value = $1.value + strlen($3.str);
  509. X        genstr($3.str);
  510. X        
  511. X        free($3.str);
  512. X    }
  513. X}
  514. X        | data8
  515. X{
  516. X    if( pass2 ) genbyte($1.value);
  517. X    $$.value = 1;
  518. X}
  519. X        | STRING
  520. X{
  521. X    if( pass1 )
  522. X        $$.value = $1.value;
  523. X    else {
  524. X        $$.value = strlen($1.str);
  525. X        genstr($1.str);
  526. X        free($1.str);
  527. X    }
  528. X}
  529. X        ;
  530. X
  531. Xwlist        : wlist ',' data16
  532. X{
  533. X    if( pass2 ) genword($3.value);
  534. X    $$.value = $1.value + 2;
  535. X}
  536. X        | data16
  537. X{
  538. X    if( pass2 ) genword($1.value);
  539. X    $$.value = 2;
  540. X}
  541. X        ;
  542. X
  543. X
  544. X
  545. X/* --------------------
  546. X * EXPRESSIONS:
  547. X *
  548. X */
  549. X
  550. Xexpr        : '*'            { $$.val.v = lc;
  551. X                      $$.val.d = 1; }
  552. X
  553. X        | '(' expr ')'        { $$.val.v = $2.val.v;
  554. X                      $$.val.d = $2.val.d; }
  555. X
  556. X        | '-' expr %prec '*'    { $$.val.v = -$2.val.v;
  557. X                      $$.val.d = $2.val.d;  }
  558. X
  559. X        | expr '|' expr        { $$.val.v = $1.val.v | $3.val.v;
  560. X                      $$.val.d = $1.val.d && $3.val.d; }
  561. X
  562. X        | expr '&' expr        { $$.val.v = $1.val.v & $3.val.v;
  563. X                      $$.val.d = $1.val.d && $3.val.d; }
  564. X
  565. X        | expr '*' expr        { $$.val.v = $1.val.v * $3.val.v;
  566. X                      $$.val.d = $1.val.d && $3.val.d; }
  567. X
  568. X        | expr '/' expr        { $$.val.v = $1.val.v / $3.val.v;
  569. X                      $$.val.d = $1.val.d && $3.val.d; }
  570. X
  571. X        | expr '%' expr        { $$.val.v = $1.val.v % $3.val.v;
  572. X                      $$.val.d = $1.val.d && $3.val.d; }
  573. X
  574. X        | expr '-' expr        { $$.val.v = $1.val.v - $3.val.v;
  575. X                      $$.val.d = $1.val.d && $3.val.d; }
  576. X
  577. X        | expr '+' expr        { $$.val.v = $1.val.v + $3.val.v;
  578. X                      $$.val.d = $1.val.d && $3.val.d; }
  579. X        | SYMBOL
  580. X{
  581. X    if( pass1 ) {
  582. X        $$.val.v = $1.sym->value;
  583. X        $$.val.d = ($1.sym->type != UNDEF);
  584. X    }
  585. X    else {
  586. X        if( $1.sym->type == UNDEF )
  587. X            error("Undefined symbol %s",$1.sym->name);
  588. X        $$.val.v = $1.sym->value;
  589. X        $$.val.d = 1;
  590. X    }
  591. X}
  592. X        | VALUE        { $$.val.v = $1.val.v; $$.val.d=1; }
  593. X        ;
  594. X
  595. X
  596. X
  597. X
  598. X
  599. X/* --------------------
  600. X * INSTRUCTIONS:
  601. X *
  602. X */
  603. X
  604. Xinstr        : NOP
  605. X                { $$.value = makeop($1.op,NULL,0); }
  606. X        | ACALL addr11
  607. X                { $$.value = makeop($1.op,&$2.mode,0); }
  608. X        | AJMP addr11
  609. X                { $$.value = makeop($1.op,&$2.mode,0); }
  610. X        | ADD two_op1
  611. X                { $$.value = makeop($1.op,&$2.mode,0); }
  612. X        | ADDC two_op1
  613. X                { $$.value = makeop($1.op,&$2.mode,0); }
  614. X        | SUBB two_op1
  615. X                { $$.value = makeop($1.op,&$2.mode,0); }
  616. X        | XRL two_op1
  617. X                { $$.value = makeop($1.op,&$2.mode,0); }
  618. X        | XRL two_op2
  619. X                { $$.value = makeop($1.op,&$2.mode,4); }
  620. X        | ANL two_op1
  621. X                { $$.value = makeop($1.op,&$2.mode,0); }
  622. X        | ANL two_op2
  623. X                { $$.value = makeop($1.op,&$2.mode,4); }
  624. X        | ANL two_op3
  625. X                { $$.value = makeop($1.op,&$2.mode,6); }
  626. X        | ORL two_op1
  627. X                { $$.value = makeop($1.op,&$2.mode,0); }
  628. X        | ORL two_op2
  629. X                { $$.value = makeop($1.op,&$2.mode,4); }
  630. X        | ORL two_op3
  631. X                { $$.value = makeop($1.op,&$2.mode,6); }
  632. X        | XCH two_op1
  633. X                { if( get_md($2.mode) == 3 )
  634. X                    error("Immediate mode is illegal");
  635. X                  $$.value = makeop($1.op,&$2.mode,0);
  636. X                }
  637. X        | INC single_op1
  638. X                { $$.value = makeop($1.op,&$2.mode,0); }
  639. X        | INC DPTR
  640. X                { $$.value = makeop($1.op,NULL,4); }
  641. X        | DEC single_op1
  642. X                { $$.value = makeop($1.op,&$2.mode,0); }
  643. X        | DA A
  644. X                { $$.value = makeop($1.op,NULL,0); }
  645. X        | DIV AB
  646. X                { $$.value = makeop($1.op,NULL,0); }
  647. X        | JMP '@' A '+' DPTR
  648. X                { $$.value = makeop($1.op,NULL,0); }
  649. X        | JMP '@' DPTR '+' A
  650. X                { $$.value = makeop($1.op,NULL,0); }
  651. X        | MUL AB
  652. X                { $$.value = makeop($1.op,NULL,0); }
  653. X        | RET
  654. X                { $$.value = makeop($1.op,NULL,0); }
  655. X        | RETI
  656. X                { $$.value = makeop($1.op,NULL,0); }
  657. X        | RL A
  658. X                { $$.value = makeop($1.op,NULL,0); }
  659. X        | RLC A
  660. X                { $$.value = makeop($1.op,NULL,0); }
  661. X        | RR A
  662. X                { $$.value = makeop($1.op,NULL,0); }
  663. X        | RRC A
  664. X                { $$.value = makeop($1.op,NULL,0); }
  665. X        | SWAP A
  666. X                { $$.value = makeop($1.op,NULL,0); }
  667. X        | XCHD two_op1
  668. X                { if( get_md($2.mode) != 2 )
  669. X                    error("Invalid addressing mode");
  670. X                  $$.value = makeop($1.op,&$2.mode,-2); }
  671. X        | CLR single_op2
  672. X                { $$.value = makeop($1.op,&$2.mode,0); }
  673. X        | CPL single_op2
  674. X                { $$.value = makeop($1.op,&$2.mode,0); }
  675. X        | SETB single_op2
  676. X                { if( get_md($2.mode) == 0 )
  677. X                    error("Invalid addressing mode");
  678. X                  $$.value = makeop($1.op,&$2.mode,-1); }
  679. X        | PUSH data8
  680. X                {
  681. X                   struct mode tmp;
  682. X                    set_md(tmp,0);
  683. X                    set_ov(tmp,0);
  684. X                    set_sz(tmp,1);
  685. X                    set_b1(tmp,$2.value);
  686. X                    $$.value = makeop($1.op,&tmp,0);
  687. X                }
  688. X        | POP data8
  689. X                {
  690. X                   struct mode tmp;
  691. X                    set_md(tmp,0);
  692. X                    set_ov(tmp,0);
  693. X                    set_sz(tmp,1);
  694. X                    set_b1(tmp,$2.value);
  695. X                    $$.value = makeop($1.op,&tmp,0);
  696. X                }
  697. X        | LJMP addr16
  698. X                { $$.value = makeop($1.op,&$2.mode,0); }
  699. X        | LCALL addr16
  700. X                { $$.value = makeop($1.op,&$2.mode,0); }
  701. X        | JC relative
  702. X                { $$.value = makeop($1.op,&$2.mode,0); }
  703. X        | JNC relative
  704. X                { $$.value = makeop($1.op,&$2.mode,0); }
  705. X        | JNZ relative
  706. X                { $$.value = makeop($1.op,&$2.mode,0); }
  707. X        | JZ relative
  708. X                { $$.value = makeop($1.op,&$2.mode,0); }
  709. X        | SJMP relative
  710. X                { $$.value = makeop($1.op,&$2.mode,0); }
  711. X        | CJNE three_op1
  712. X                { $$.value = makeop($1.op,&$2.mode,0); }
  713. X        | JB two_op4
  714. X                { $$.value = makeop($1.op,&$2.mode,0); }
  715. X        | JNB two_op4
  716. X                { $$.value = makeop($1.op,&$2.mode,0); }
  717. X        | JBC two_op4
  718. X                { $$.value = makeop($1.op,&$2.mode,0); }
  719. X        | DJNZ two_op5
  720. X                { $$.value = makeop($1.op,&$2.mode,0); }
  721. X        | MOV two_op1
  722. X                { $$.value = makeop($1.op,&$2.mode,0); }
  723. X        | MOV two_op2
  724. X                { $$.value = makeop($1.op,&$2.mode,4); }
  725. X        | MOV two_op6
  726. X                { $$.value = makeop($1.op,&$2.mode,6); }
  727. X
  728. X
  729. X        | MOVC A ',' '@' A '+' DPTR
  730. X                { $$.value = makeop($1.op,NULL,0); }
  731. X        | MOVC A ',' '@' DPTR '+' A
  732. X                { $$.value = makeop($1.op,NULL,0); }
  733. X        | MOVC A ',' '@' A '+' PC
  734. X                { $$.value = makeop($1.op,NULL,1); }
  735. X        | MOVC A ',' '@' PC '+' A
  736. X                { $$.value = makeop($1.op,NULL,1); }
  737. X
  738. X        | MOVX A ',' '@' regi
  739. X                { $$.value = makeop($1.op,NULL,$5.value); }
  740. X        | MOVX A ',' '@' DPTR
  741. X                { $$.value = makeop($1.op,NULL,2); }
  742. X        | MOVX '@' regi ',' A
  743. X                { $$.value = makeop($1.op,NULL,$3.value+3); }
  744. X        | MOVX '@' DPTR ',' A
  745. X                { $$.value = makeop($1.op,NULL,5); }
  746. X        ;
  747. X
  748. X
  749. X
  750. X
  751. X/* --------------------
  752. X * ADDRESSING MODES:
  753. X *
  754. X */
  755. X
  756. Xtwo_op1        : A ',' reg
  757. X                {
  758. X                    set_md($$.mode,0);
  759. X                    set_ov($$.mode, $3.value);
  760. X                    set_sz($$.mode, 0);
  761. X                }
  762. X        | A ',' data8
  763. X                {
  764. X                    set_md($$.mode,1);
  765. X                    set_ov($$.mode,0);
  766. X                    set_sz($$.mode,1);
  767. X                    set_b1($$.mode,$3.value);
  768. X                }
  769. X        | A ',' '@' regi
  770. X                {
  771. X                    set_md($$.mode,2);
  772. X                    set_ov($$.mode,$4.value);
  773. X                    set_sz($$.mode,0);
  774. X                }
  775. X        | A ',' '#' data8
  776. X                {
  777. X                    set_md($$.mode,3);
  778. X                    set_ov($$.mode,0);
  779. X                    set_sz($$.mode,1);
  780. X                    set_b1($$.mode,$4.value);
  781. X                }
  782. X        ;
  783. X
  784. Xtwo_op2        : data8 ',' A
  785. X                {
  786. X                    set_md($$.mode,0);
  787. X                    set_ov($$.mode,0);
  788. X                    set_sz($$.mode,1);
  789. X                    set_b1($$.mode,$1.value);
  790. X                }
  791. X        | data8 ',' '#' data8
  792. X                {
  793. X                    set_md($$.mode,1);
  794. X                    set_ov($$.mode,0);
  795. X                    set_sz($$.mode,2);
  796. X                    set_b1($$.mode,$1.value);
  797. X                    set_b2($$.mode,$4.value);
  798. X                }
  799. X        ;
  800. X
  801. Xtwo_op3        : C ',' bit
  802. X                {
  803. X                    set_md($$.mode,0);
  804. X                    set_ov($$.mode,0);
  805. X                    set_sz($$.mode,1);
  806. X                    set_b1($$.mode,$3.value);
  807. X                }
  808. X        | C ',' '/' bit
  809. X                {
  810. X                    set_md($$.mode,1);
  811. X                    set_ov($$.mode,0);
  812. X                    set_sz($$.mode,1);
  813. X                    set_b1($$.mode,$4.value);
  814. X                }
  815. X        | C ',' '!' bit
  816. X                {
  817. X                    set_md($$.mode,1);
  818. X                    set_ov($$.mode,0);
  819. X                    set_sz($$.mode,1);
  820. X                    set_b1($$.mode,$4.value);
  821. X                }
  822. X        ;
  823. X
  824. Xtwo_op4        : bit ',' rel
  825. X                {
  826. X                    set_md($$.mode,0);
  827. X                    set_ov($$.mode,0);
  828. X                    set_sz($$.mode,2);
  829. X                    set_b1($$.mode,$1.value);
  830. X                    set_b2($$.mode,$3.value);
  831. X                }
  832. X        ;
  833. X
  834. Xtwo_op5        : reg ',' rel2
  835. X                {
  836. X                    set_md($$.mode,0);
  837. X                    set_ov($$.mode,$1.value);
  838. X                    set_sz($$.mode,1);
  839. X                    set_b1($$.mode,$3.value);
  840. X                }
  841. X        | data8 ',' rel
  842. X                {
  843. X                    set_md($$.mode,1);
  844. X                    set_ov($$.mode,0);
  845. X                    set_sz($$.mode,2);
  846. X                    set_b1($$.mode,$1.value);
  847. X                    set_b2($$.mode,$3.value);
  848. X                }
  849. X        ;
  850. X
  851. Xtwo_op6        : reg ',' A
  852. X                {
  853. X                    set_md($$.mode,0);
  854. X                    set_ov($$.mode,$1.value);
  855. X                    set_sz($$.mode,0);
  856. X                }
  857. X        | reg ',' data8
  858. X                {
  859. X                    set_md($$.mode,1);
  860. X                    set_ov($$.mode,$1.value);
  861. X                    set_sz($$.mode,1);
  862. X                    set_b1($$.mode,$3.value);
  863. X                }
  864. X        | reg ',' '#' data8
  865. X                {
  866. X                    set_md($$.mode,2);
  867. X                    set_ov($$.mode,$1.value);
  868. X                    set_sz($$.mode,1);
  869. X                    set_b1($$.mode,$4.value);
  870. X                }
  871. X        | data8 ',' reg
  872. X                {
  873. X                    set_md($$.mode,3);
  874. X                    set_ov($$.mode,$3.value);
  875. X                    set_sz($$.mode,1);
  876. X                    set_b1($$.mode,$1.value);
  877. X                }
  878. X        | data8 ',' data8
  879. X                {
  880. X                    set_md($$.mode,4);
  881. X                    set_ov($$.mode,0);
  882. X                    set_sz($$.mode,2);
  883. X                    set_b1($$.mode,$3.value);
  884. X                    set_b2($$.mode,$1.value);
  885. X                }
  886. X        | data8 ',' '@' regi
  887. X                {
  888. X                    set_md($$.mode,5);
  889. X                    set_ov($$.mode,$4.value);
  890. X                    set_sz($$.mode,1);
  891. X                    set_b1($$.mode,$1.value);
  892. X                }
  893. X        | '@' regi ',' A
  894. X                {
  895. X                    set_md($$.mode,6);
  896. X                    set_ov($$.mode,$2.value);
  897. X                    set_sz($$.mode,0);
  898. X                }
  899. X        | '@' regi ',' data8
  900. X                {
  901. X                    set_md($$.mode,7);
  902. X                    set_ov($$.mode,$2.value);
  903. X                    set_sz($$.mode,1);
  904. X                    set_b1($$.mode,$4.value);
  905. X                }
  906. X        | '@' regi ',' '#' data8
  907. X                {
  908. X                    set_md($$.mode,8);
  909. X                    set_ov($$.mode,$2.value);
  910. X                    set_sz($$.mode,1);
  911. X                    set_b1($$.mode,$5.value);
  912. X                }
  913. X        | DPTR ',' '#' data16
  914. X            {
  915. X                set_md($$.mode,9);
  916. X                set_ov($$.mode,0);
  917. X                set_sz($$.mode,2);
  918. X                set_b1($$.mode, ($4.value & 0xff00) >> 8 );
  919. X                set_b2($$.mode, ($4.value & 0x00ff) );
  920. X            }
  921. X        | C ',' bit
  922. X                {
  923. X                    set_md($$.mode,10);
  924. X                    set_ov($$.mode,0);
  925. X                    set_sz($$.mode,1);
  926. X                    set_b1($$.mode,$3.value);
  927. X                }
  928. X    /*
  929. X     * Following two productions cannot be represented by:
  930. X     *
  931. X     *    bit ',' C
  932. X     *
  933. X     * Because yacc gives tons of reduce/reduce errors if
  934. X      * that is attempted.
  935. X     *
  936. X     */
  937. X        | data8 ',' C
  938. X                {
  939. X                    set_md($$.mode,11);
  940. X                    set_ov($$.mode,0);
  941. X                    set_sz($$.mode,1);
  942. X                    set_b1($$.mode,$1.value);
  943. X                }
  944. X        | data8 BITPOS ',' C
  945. X{
  946. X    if( pass2 ) {
  947. X        if( !isbit8($1.value) )
  948. X            warning("Bit address exceeds 8-bits");
  949. X        if( isbmram($1.value) )
  950. X            set_b1($$.mode, ($1.value-0x20)*8+ $2.value );
  951. X        else if( isbmsfr($1.value) )
  952. X            set_b1($$.mode, $1.value + $2.value );
  953. X        else
  954. X            warning("Invalid bit addressable RAM location");
  955. X    }
  956. X    set_md($$.mode,11);
  957. X    set_ov($$.mode,0);
  958. X    set_sz($$.mode,1);
  959. X}
  960. X        ;
  961. X
  962. X
  963. Xsingle_op1    : A
  964. X                {
  965. X                    set_md($$.mode,0);
  966. X                    set_ov($$.mode,0);
  967. X                    set_sz($$.mode,0);
  968. X                }
  969. X
  970. X        | reg
  971. X                {
  972. X                    set_md($$.mode,1);
  973. X                    set_ov($$.mode,$1.value);
  974. X                    set_sz($$.mode,0);
  975. X                }
  976. X        | data8
  977. X                {
  978. X                    set_md($$.mode,2);
  979. X                    set_ov($$.mode,0);
  980. X                    set_sz($$.mode,1);
  981. X                    set_b1($$.mode,$1.value);
  982. X                }
  983. X        | '@' regi
  984. X                {
  985. X                    set_md($$.mode,3);
  986. X                    set_ov($$.mode,$2.value);
  987. X                    set_sz($$.mode,0);
  988. X                }
  989. X        ;
  990. X
  991. Xsingle_op2    : A
  992. X                {
  993. X                    set_md($$.mode,0);
  994. X                    set_ov($$.mode,0);
  995. X                    set_sz($$.mode,0);
  996. X                }
  997. X        | C
  998. X                {
  999. X                    set_md($$.mode,1);
  1000. X                    set_ov($$.mode,0);
  1001. X                    set_sz($$.mode,0);
  1002. X                }
  1003. X        | bit
  1004. X                {
  1005. X                    set_md($$.mode,2);
  1006. X                    set_ov($$.mode,0);
  1007. X                    set_sz($$.mode,1);
  1008. X                    set_b1($$.mode,$1.value);
  1009. X                }
  1010. X        ;
  1011. X
  1012. Xthree_op1    : A ',' data8 ',' rel
  1013. X                {
  1014. X                    set_md($$.mode,0);
  1015. X                    set_ov($$.mode,0);
  1016. X                    set_sz($$.mode,2);
  1017. X                    set_b1($$.mode,$3.value);
  1018. X                    set_b2($$.mode,$5.value);
  1019. X                }
  1020. X        | A ',' '#' data8 ',' rel
  1021. X                {
  1022. X                    set_md($$.mode,1);
  1023. X                    set_ov($$.mode,0);
  1024. X                    set_sz($$.mode,2);
  1025. X                    set_b1($$.mode,$4.value);
  1026. X                    set_b2($$.mode,$6.value);
  1027. X                }
  1028. X        | reg ',' '#' data8 ',' rel
  1029. X                {
  1030. X                    set_md($$.mode,2);
  1031. X                    set_ov($$.mode,$1.value);
  1032. X                    set_sz($$.mode,2);
  1033. X                    set_b1($$.mode,$4.value);
  1034. X                    set_b2($$.mode,$6.value);
  1035. X                }
  1036. X        | '@' regi ',' '#' data8 ',' rel
  1037. X                {
  1038. X                    set_md($$.mode,3);
  1039. X                    set_ov($$.mode,$2.value);
  1040. X                    set_sz($$.mode,2);
  1041. X                    set_b1($$.mode,$5.value);
  1042. X                    set_b2($$.mode,$7.value);
  1043. X                }
  1044. X        ;
  1045. X
  1046. Xrel        : expr
  1047. X{
  1048. X        long offset;
  1049. X        if( pass2 ) {
  1050. X            offset = $1.val.v - (lc+3);
  1051. X            if( offset > 127 || offset < -128 )
  1052. X               warning("Relative offset exceeds -128 / +127");
  1053. X            $$.value = offset;
  1054. X        }
  1055. X}
  1056. X        ;
  1057. X
  1058. X/*
  1059. X * This production differs from the above, by 1 number!
  1060. X *
  1061. X */
  1062. X
  1063. Xrel2        : expr
  1064. X{
  1065. X        long offset;
  1066. X        if( pass2 ) {
  1067. X            offset = $1.val.v - (lc+2); /* different! */
  1068. X            if( offset > 127 || offset < -128 )
  1069. X               warning("Relative offset exceeds -128 / +127");
  1070. X            $$.value = offset;
  1071. X        }
  1072. X}
  1073. X        ;
  1074. X
  1075. X
  1076. Xbit        : bitv BITPOS
  1077. X{
  1078. X    if( pass2 ) {
  1079. X        if( !isbit8($1.value) )
  1080. X            warning("Bit address exceeds 8-bits");
  1081. X        if( isbmram($1.value) )
  1082. X            $$.value = ($1.value-0x20)*8+$2.value;
  1083. X        else if( isbmsfr($1.value) )
  1084. X            $$.value = $1.value + $2.value;
  1085. X        else
  1086. X            warning("Invalid bit addressable RAM location");
  1087. X    }
  1088. X}
  1089. X        | bitv
  1090. X{
  1091. X    if( pass2 ) {
  1092. X        if( !isbit8($1.value) )
  1093. X            warning("Bit address exceeds 8-bits");
  1094. X        $$.value = $1.value;
  1095. X    }
  1096. X}
  1097. X        ;
  1098. X
  1099. Xbitv        : SYMBOL
  1100. X{
  1101. X    if( $1.sym->type == UNDEF && pass2 )
  1102. X        error("Symbol %s undefined",$1.sym->name);
  1103. X    $$.value = $1.sym->value;
  1104. X}
  1105. X        | VALUE        { $$.value = $1.value; }
  1106. X        ;
  1107. X
  1108. Xreg        : R0        { $$.value = 0; }
  1109. X        | R1        { $$.value = 1; }
  1110. X        | R2        { $$.value = 2; }
  1111. X        | R3        { $$.value = 3; }
  1112. X        | R4        { $$.value = 4; }
  1113. X        | R5        { $$.value = 5; }
  1114. X        | R6        { $$.value = 6; }
  1115. X        | R7        { $$.value = 7; }
  1116. X        ;
  1117. X
  1118. Xregi        : R0        { $$.value = 0; }
  1119. X        | R1        { $$.value = 1; }
  1120. X        | R2
  1121. X                { $$.value = 0;
  1122. X                  warning("Illegal indirect register: @r2"); }
  1123. X        | R3
  1124. X                { $$.value = 0;
  1125. X                  warning("Illegal indirect register: @r3"); }
  1126. X        | R4
  1127. X                { $$.value = 0;
  1128. X                  warning("Illegal indirect register: @r4"); }
  1129. X        | R5
  1130. X                { $$.value = 0;
  1131. X                  warning("Illegal indirect register: @r5"); }
  1132. X        | R6
  1133. X                { $$.value = 0;
  1134. X                  warning("Illegal indirect register: @r6"); }
  1135. X        | R7
  1136. X                { $$.value = 0;
  1137. X                  warning("Illegal indirect register: @r7"); }
  1138. X        ;
  1139. X
  1140. Xdata8        : expr
  1141. X{
  1142. X    if( pass2 ) {
  1143. X        if( !isbit8($1.val.v) )
  1144. X            warning("Expression greater than 8-bits");
  1145. X    }
  1146. X    $$.value = $1.val.v;
  1147. X}
  1148. X        ;
  1149. X
  1150. Xdata16        : expr
  1151. X{
  1152. X    if( pass2 ) {
  1153. X        if( !isbit16($1.val.v) )
  1154. X            warning("Expression greater than 16-bits");
  1155. X    }
  1156. X    $$.value = $1.val.v;
  1157. X}
  1158. X        ;
  1159. X
  1160. Xaddr11        : expr
  1161. X{
  1162. X        if( pass2 ) {
  1163. X            if( !isbit16($1.val.v)  )
  1164. X                warning("Address greater than 16-bits");
  1165. X            if( ($1.val.v & size11) != ((lc+2) & size11) )
  1166. X                warning("Address outside current 2K page");
  1167. X        }
  1168. X        set_md($$.mode,0);
  1169. X        set_ov($$.mode, ($1.val.v&0x0700)>>3 );
  1170. X        set_sz($$.mode,1);
  1171. X        set_b1($$.mode,$1.val.v&0x00ff);
  1172. X}
  1173. X        ;
  1174. X
  1175. Xaddr16        : expr
  1176. X{
  1177. X        if( pass2 ) {
  1178. X            if( !isbit16($1.val.v)  )
  1179. X                warning("Address greater than 16-bits");
  1180. X        }
  1181. X        set_md($$.mode,0);
  1182. X        set_ov($$.mode, 0 );
  1183. X        set_sz($$.mode,2);
  1184. X        set_b1($$.mode, ($1.val.v & 0xff00 ) >> 8 );
  1185. X        set_b2($$.mode, ($1.val.v & 0x00ff ) );
  1186. X}
  1187. X        ;
  1188. X
  1189. Xrelative    : expr
  1190. X{
  1191. X        long offset;
  1192. X        if( pass2 ) {
  1193. X            offset = $1.val.v - (lc+2);
  1194. X            if( offset>127 || offset<-128 )
  1195. X               warning("Relative offset exceeds -128 / +127");
  1196. X        }
  1197. X        set_md($$.mode,0);
  1198. X        set_ov($$.mode,0);
  1199. X        set_sz($$.mode,1);
  1200. X        set_b1($$.mode,offset);
  1201. X
  1202. X}
  1203. X        ;
  1204. X
  1205. X%%
  1206. X
  1207. X/* ---------------------------------------------------------------------- */
  1208. X
  1209. Xyyerror(s)
  1210. Xchar *s;
  1211. X{
  1212. X    error(s);
  1213. X}
  1214. X
  1215. X
  1216. X/* ----------------------------------------------------------------------
  1217. X * error:
  1218. X *    Uses semi-variable arguments. This causes immediate assembler
  1219. X *    termination.
  1220. X */
  1221. X
  1222. Xerror(cs,a1,a2,a3,a4,a5,a6)
  1223. Xchar *cs,*a1,*a2,*a3,*a4,*a5,*a6;
  1224. X{
  1225. X    fprintf(stderr,"File: %s, line: %d, ",asmfile,lineno);
  1226. X    fprintf(stderr,cs,a1,a2,a3,a4,a5,a6);
  1227. X    fprintf(stderr,".\n");
  1228. X    longjmp(main_env,1);
  1229. X}
  1230. X
  1231. X/* ----------------------------------------------------------------------
  1232. X * warning:
  1233. X *    Produce error message. This will abort assembly at
  1234. X *    the end of the current pass.
  1235. X *
  1236. X */
  1237. X
  1238. Xwarning(cs,a1,a2,a3,a4,a5,a6)
  1239. Xchar *cs,*a1,*a2,*a3,*a4,*a5,*a6;
  1240. X{
  1241. X    fatal++;
  1242. X    fprintf(stderr,"File: %s, line: %d, ",asmfile,lineno);
  1243. X    fprintf(stderr,cs,a1,a2,a3,a4,a5,a6);
  1244. X    fprintf(stderr,".\n");
  1245. X}
  1246. X
  1247. X
  1248. X/* ----------------------------------------------------------------------
  1249. X * makeop:
  1250. X *    This function makes an opcode based on the instruction symbol table
  1251. X *    entry, and an addressing mode structure.
  1252. X *    This function is called from both passes, but
  1253. X *    only generates code in pass 2.
  1254. X *
  1255. X *    Resultant opcode bytes are passed to genbyte().
  1256. X *
  1257. X *    Returns the nuumber of bytes that the instruction
  1258. X *    occupies.
  1259. X *
  1260. X */
  1261. X
  1262. Xmakeop(op,m,add)
  1263. Xstruct opcode *op;
  1264. Xstruct mode *m;
  1265. X{
  1266. X    register unsigned int newop;
  1267. X
  1268. X    if( m == NULL ) {
  1269. X        if(pass2) genbyte(op->bytes[0+add]);
  1270. X        return(1);
  1271. X    }
  1272. X
  1273. X    if( pass2 ) {
  1274. X        newop = op->bytes[ get_md(*m)+add ] | get_ov(*m);
  1275. X        genbyte(newop);
  1276. X        if( get_sz(*m) > 0 ) genbyte( get_b1(*m) );
  1277. X        if( get_sz(*m) > 1 ) genbyte( get_b2(*m) );
  1278. X    }
  1279. X    return( get_sz(*m)+1 );
  1280. X}
  1281. X
  1282. X
  1283. X/* ----------------------------------------------------------------------
  1284. X * inclc:
  1285. X *    Increments the Location Counter by 'i' amount.
  1286. X *    Check to see if 'i' overflows 64K.
  1287. X *    Checks to see if assembler is overlapping previous sections
  1288. X *    of code. (using a large bit field).
  1289. X *
  1290. X */
  1291. X
  1292. X#define indx(a) ( (a)/(sizeof(long)*8) )
  1293. X#define bit(a)    ( 1 << ((a)%(sizeof(long)*8)) )
  1294. X
  1295. X#define getloc(a) (regions[indx(a)] & bit(a))
  1296. X#define setloc(a) (regions[indx(a)] |= bit(a))
  1297. X
  1298. Xinclc(i)
  1299. X{
  1300. X    static unsigned long regions[ 0x10000/(sizeof(long)*8) ];
  1301. X
  1302. X    while(i-- > 0) {
  1303. X        if( pass2 && getloc(lc) )
  1304. X            error("Location counter overlaps");
  1305. X        if( pass2 ) setloc(lc);
  1306. X        lc += 1;
  1307. X    }
  1308. X        
  1309. X    if( lc > 0xffff )
  1310. X        error("Location counter has exceeded 16-bits");
  1311. X}
  1312. X
  1313. X/* ----------------------------------------------------------------------
  1314. X * padline:
  1315. X *    This routine returns a new string, which is equivilant to
  1316. X *    'line' except that all tabs have been expanded to spaces, and
  1317. X *    the total length has been truncated to 60 chars.
  1318. X */
  1319. X
  1320. Xchar *padline(line)
  1321. Xchar *line;
  1322. X{
  1323. X    static char newline[61];
  1324. X    char *p1;
  1325. X    int pos=0,nxtpos;
  1326. X
  1327. X    for(p1=line; pos<sizeof(newline)-1 && *p1; p1++ ) {
  1328. X        if( *p1 == '\t' ) {
  1329. X            nxtpos = pos+8-pos%8;
  1330. X            while(pos<sizeof(newline)-1 && pos <= nxtpos)
  1331. X                newline[pos++] = ' ';
  1332. X        } else if( *p1 != '\n' )
  1333. X            newline[pos++]= *p1;
  1334. X    }
  1335. X    newline[pos] = '\0';
  1336. X    return(newline);
  1337. X}
  1338. X
  1339. X
  1340. X/* ----------------------------------------------------------------------
  1341. X * dumplist:
  1342. X *    Outputs the current location counter, bytebuf[] array, and
  1343. X *    the string 'txt' to the listing file.
  1344. X *    This routine is called for every source line encountered in the
  1345. X *    source file. (Only in pass 2, and if listing is turned on).
  1346. X *
  1347. X */
  1348. X
  1349. Xdumplist(txt,show)
  1350. Xchar *txt;
  1351. X{
  1352. X    int i,j;
  1353. X
  1354. X    fprintf(listing,show?"%04X: ":"      ",lc);
  1355. X
  1356. X    j=0;
  1357. X    for(i=0; i<bytecount; i++ ) {
  1358. X        fprintf(listing,"%02X ",bytebuf[i]);
  1359. X        if( ++j >= 4 ) {
  1360. X            j = 0;
  1361. X            fprintf(listing,"\n      ");
  1362. X        }
  1363. X    }
  1364. X    while(++j <= 4)
  1365. X        fprintf(listing,"   ");
  1366. X
  1367. X    fprintf(listing," %s\n",padline(txt));
  1368. X}
  1369. X
  1370. X/* ----------------------------------------------------------------------
  1371. X * gen* routines:
  1372. X *    Place information into the bytebuf[] array, and also
  1373. X *    call emitbyte with the byte.
  1374. X *
  1375. X */
  1376. X
  1377. Xgenbyte(b)
  1378. Xint b;
  1379. X{
  1380. X    if( bytecount < sizeof(bytebuf) )
  1381. X        bytebuf[bytecount++] = b;
  1382. X    emitbyte(b);
  1383. X}
  1384. X
  1385. Xgenstr(s)
  1386. Xchar *s;
  1387. X{
  1388. X    while( *s )
  1389. X        genbyte(*s++);
  1390. X}
  1391. X
  1392. Xgenword(w)
  1393. Xunsigned long w;
  1394. X{
  1395. X    genbyte( (w & 0xff00) >> 8 );
  1396. X    genbyte( (w & 0x00ff) );
  1397. X}
  1398. X
  1399. END_OF_FILE
  1400. if test 22290 -ne `wc -c <'as31.y'`; then
  1401.     echo shar: \"'as31.y'\" unpacked with wrong size!
  1402. fi
  1403. # end of 'as31.y'
  1404. fi
  1405. if test -f 'as31.man' -a "${1}" != "-c" ; then 
  1406.   echo shar: Will not clobber existing file \"'as31.man'\"
  1407. else
  1408. echo shar: Extracting \"'as31.man'\" \(9374 characters\)
  1409. sed "s/^X//" >'as31.man' <<'END_OF_FILE'
  1410. X.TH AS31 1L
  1411. X.SH NAME
  1412. Xas31 - An Intel 8031/8051 assembler
  1413. X.SH SYNOPSIS
  1414. X.B as31
  1415. X[
  1416. X.B \-Fformat
  1417. X] [
  1418. X.B \-Aarg
  1419. X] [
  1420. X.B \-l
  1421. X]
  1422. X.BR infile.asm
  1423. X.SH DESCRIPTION
  1424. X.I As31
  1425. Xassembles
  1426. X.IR infile.asm
  1427. Xinto one of several different output formats. The output
  1428. Xwill be in a file called infile.obj. The .asm extenstion
  1429. Xis required.
  1430. X
  1431. X.SH OPTIONS
  1432. XThe options must appear before the input file name. Both
  1433. Xoptions are optional. The text of each flag must appear
  1434. Xon the same argument as the flag. For example, "-Fod" is a
  1435. Xvalid argument, but "-F od" is not.
  1436. X.TP
  1437. X.I \-Fformat
  1438. XThis options specifies the output format that is to be used.
  1439. X.IP
  1440. XCurrently the only options available for this are:
  1441. X.RS
  1442. X.IP "tdr"
  1443. XThis format generates an asci file of hex digits formatted in such a
  1444. Xway, so that they can be read by tdr's debugger. An argument can be
  1445. Xspecified (See -A option) which will pass a format specific string to
  1446. Xthe format generator. In this case, the argument string represents
  1447. Xan offset to add to the location counter. This offset is
  1448. Xspecified in decimal and defaults to 64*1024 (0x10000). To specify
  1449. Xand offset of 100, you would need "-Ftdr -A100" when invoking the
  1450. Xassembler.
  1451. X
  1452. X.IP "byte"
  1453. XThis format is simply an address and a byte on each line, in ascii.
  1454. XNo -A option is used.
  1455. X
  1456. X.IP "od"
  1457. XThis format is similar to the output from od(1). The format 
  1458. Xconsists of an address followed by sixteen hexadecimal bytes, followed
  1459. Xby the equivilant ASCII. No -A option is used.
  1460. X
  1461. X.IP "srec2, srec3, srec4"
  1462. XThe srecord generator is capable of generating output with any one
  1463. Xof 2, 3, or 4 byte addresses. The -A option can be used to set the
  1464. Xbase address offset, the default here is 0x0000 (unlike \fBtdr\fP).
  1465. X.RE
  1466. X.IP
  1467. XNOTE: This assembler allows for the output formats to be expanded to
  1468. Xinclude many different output formats.
  1469. X.IP \-Aarg
  1470. XThis option specifies a format specific string which is
  1471. Xpassed to the format generator. Both format "tdr" and the srecord
  1472. Xformats use this option.
  1473. X.IP \-l
  1474. XThis option tells the assembler to also generate a listing file.
  1475. XA listing will be placed in the file infile.lst. Where 'infile' is
  1476. Xthe file that is being assembled. This option may appear
  1477. Xanywhere before infile.asm. The option must occur isolated on
  1478. Xthe command line.
  1479. X.IP
  1480. XThe listing file shows the assembler generated code in hex, and up to
  1481. X60 characters are retained from the source file.
  1482. X.DE
  1483. X
  1484. X.SH "ASSEMBLER INSTRUCTIONS"
  1485. XThis assembler accepts standard 8031/8051 instruction formats.
  1486. XBelow is a list of instructions
  1487. Xand addressing modes.
  1488. X.IP
  1489. X.RS
  1490. X.nf
  1491. X.ta +1i +2i +1i +1i
  1492. XINSTRUCTION        BYTES    CYCLES
  1493. X-----------        -----    ------
  1494. XACALL    addr11        2    24
  1495. XADD    A, #data8        2    12
  1496. XADD    A, @Ri        1    12
  1497. XADD    A, Rn        1    12
  1498. XADD    A, direct        2    12
  1499. XADDC    A, #data8        2    12
  1500. XADDC    A, @Ri        1    12
  1501. XADDC    A, Rn        1    12
  1502. XADDC    A, direct        2    12
  1503. XAJMP    addr11        2    24
  1504. XANL    A, #data8        2    12
  1505. XANL    A, @Ri        1    12
  1506. XANL    A, Rn        1    12
  1507. XANL    A, direct        2    12
  1508. XANL    C, /bit        2    24
  1509. XANL    C, !bit        2    24
  1510. XANL    C, bit        2    24
  1511. XANL    direct, #data8        3    24
  1512. XANL    direct, A        2    12
  1513. XCJNE    @Ri, #data8, rel        3    24
  1514. XCJNE    A, #data8, rel        3    24
  1515. XCJNE    A, direct, rel        3    24
  1516. XCJNE    Rn, #data8, rel        3    24
  1517. XCLR    A        1    12
  1518. XCLR    C        1    12
  1519. XCLR    bit        2    12
  1520. XCPL    A        1    12
  1521. XCPL    C        1    12
  1522. XCPL    bit        2    12
  1523. XDA    A        1    12
  1524. XDEC    @Ri        1    12
  1525. XDEC    A        1    12
  1526. XDEC    DPTR        1    12
  1527. XDEC    Rn        1    12
  1528. XDEC    direct        2    12
  1529. XDIV    AB        1    48
  1530. XDJNZ    Rn, rel        2    24
  1531. XDJNZ    direct, rel        3    24
  1532. XINC    @Ri        1    12
  1533. XINC    A        1    12
  1534. XINC    DPTR        1    24
  1535. XINC    Rn        1    12
  1536. XINC    direct        2    12
  1537. XJB    bit, rel        3    24
  1538. XJBC    bit, rel        3    24
  1539. XJC    relative        2    24
  1540. XJMP    @A + DPTR        1    24
  1541. XJMP    @DPTR + A        1    24
  1542. XJNB    bit, rel        3    24
  1543. XJNC    relative        2    24
  1544. XJNZ    relative        2    24
  1545. XJZ    relative        2    24
  1546. XLCALL    addr16        3    24
  1547. XLJMP    addr16        3    24
  1548. XMOV    @Ri, #data8        2    12
  1549. XMOV    @Ri, A        1    12
  1550. XMOV    @Ri, direct        2    24
  1551. XMOV    A, #data8        2    12
  1552. XMOV    A, @Ri        1    12
  1553. XMOV    A, Rn        1    12
  1554. XMOV    A, direct        2    12
  1555. XMOV    C, bit        2    12
  1556. XMOV    DPTR, #data16        3    24
  1557. XMOV    Rn, #data8        2    12
  1558. XMOV    Rn, A        1    12
  1559. XMOV    Rn, direct        2    24
  1560. XMOV    bit, C        2    24
  1561. XMOV    direct, #data8        3    24
  1562. XMOV    direct, @Ri        2    24
  1563. XMOV    direct, A        2    12
  1564. XMOV    direct, Rn        2    24
  1565. XMOV    direct, direct        3    24
  1566. XMOVC    A, @A + DPTR        1    24
  1567. XMOVC    A, @A + PC        1    24
  1568. XMOVC    A, @DPTR + A        1    24
  1569. XMOVC    A, @PC + A        1    24
  1570. XMOVX    @DPTR, A        1    12
  1571. XMOVX    @Ri, A        1    24
  1572. XMOVX    A, @DPTR        1    24
  1573. XMOVX    A, @Ri        1    24
  1574. XMUL    AB        1    48
  1575. XNOP            1    12
  1576. XORL    A, #data8        2    12
  1577. XORL    A, @Ri        1    12
  1578. XORL    A, Rn        1    12
  1579. XORL    A, direct        2    12
  1580. XORL    C, /bit        2    24
  1581. XORL    C, !bit        2    24
  1582. XORL    C, bit        2    24
  1583. XORL    direct, #data8        3    24
  1584. XORL    direct, A        2    12
  1585. XPOP    direct        2    24
  1586. XPUSH    direct        2    24
  1587. XRET            1    24
  1588. XRETI            1    24
  1589. XRL    A        1    12
  1590. XRLC    A        1    12
  1591. XRR    A        1    12
  1592. XRRC    A        1    12
  1593. XSETB    A        1    12
  1594. XSETB    bit        2    12
  1595. XSJMP    relative        2    24
  1596. XSUBB    A, #data8        2    12
  1597. XSUBB    A, @Ri        1    12
  1598. XSUBB    A, Rn        1    12
  1599. XSUBB    A, direct        2    12
  1600. XSWAP    A        1    12
  1601. XXCH    A, #data8        2    12
  1602. XXCH    A, @Ri        1    12
  1603. XXCH    A, Rn        1    12
  1604. XXCH    A, direct        2    12
  1605. XXCHD    A, #data8        2    12
  1606. XXCHD    A, @Ri        1    12
  1607. XXCHD    A, Rn        1    12
  1608. XXCHD    A, direct        2    12
  1609. XXRL    A, #data8        2    12
  1610. XXRL    A, @Ri        1    12
  1611. XXRL    A, Rn        1    12
  1612. XXRL    A, direct        2    12
  1613. XXRL    direct, #data8        3    12
  1614. XXRL    direct, A        2    12
  1615. X.fi
  1616. X.RE
  1617. X
  1618. X.SH "ASSEMBLER DIRECTIVES"
  1619. XAs31 includes the following assembler directives:
  1620. X.IP ".ORG expr"
  1621. XStart assembling at the address specified by the expression expr.
  1622. XAn error occurs if the assembler starts assembling over an address
  1623. Xspace that has previously been assembled into.
  1624. X
  1625. X.IP ".EQU symbol, expr"
  1626. XSet symbol to the value of expr. The value for expr must be
  1627. Xknown during the first pass, when the line containing the .EQU
  1628. Xis encountered.
  1629. X
  1630. X.IP ".BYTE expr, expr, ..."
  1631. XAssemble the bytes specified by the expression into memory. A
  1632. Xstring may also be specified with this directive.
  1633. X
  1634. X.IP ".WORD expr, expr, ..."
  1635. XAssemble the words specified by the expression into memory.
  1636. XThe byte ordering used, is that used by the 8031.
  1637. X
  1638. X.IP ".FLAG symbol1, symbol.[0-7]"
  1639. XSets symbol1 to the bit address specified by the symbol.[0-7]
  1640. Xexpression. Where [0-7] denotes a character between 0 and 7.
  1641. XThe resulting bit address is checked to see if it is a valid bit
  1642. Xaddress.
  1643. X
  1644. X.IP ".END"
  1645. XThis directive is ignored.
  1646. X
  1647. X.IP ".SKIP expr"
  1648. XAdds the value of expr to the location counter. Used
  1649. Xto reserve a block of uninitialized data. Expr should
  1650. Xbe in bytes.
  1651. X
  1652. X.SH "LEXICAL CONVENTIONS"
  1653. X.IP "-"
  1654. XAll characters following a semi-colon are ignored until a newline
  1655. Xis encountered.
  1656. X
  1657. X.IP "-"
  1658. XAll numbers default to decimal, unless the number starts with
  1659. Xone of the following:
  1660. X.RS
  1661. X.IP "0x or 0X"
  1662. XThis indicates a hexadecimal number. ie. 0x00ff
  1663. X.IP "0b or 0B"
  1664. XThis indicates a binary number. (1's and 0's). ie. 0b1100110010
  1665. X.IP "0"
  1666. XThis indicates an octal number. ie. 0377
  1667. X.RE
  1668. X.IP "-"
  1669. XAll numbers default to decimal, unless the number ends with
  1670. Xone of the following characters:
  1671. X.RS
  1672. X.IP "b or B"
  1673. XThis indicates a binary number. Unless 0x was used above.
  1674. Xie. 1010101b
  1675. X.IP "h or H"
  1676. XThis always indicates a hex number, However the if the first
  1677. Xcharacter is non-numerical, then either 0x or 0 must be specified.
  1678. XThis avoids confusing the assembler into thinking a hex number is
  1679. Xa symbol.
  1680. XFor example: 0ffh, 0xffh, 0XffH, 20h, 0x20 and 020h are means
  1681. Xto specify a valid hexdigit. But the following are not:
  1682. Xffh, 0ff.
  1683. X.IP "d or D"
  1684. XThis forces a number to decimal. Unless 0X was used. ie. 129d
  1685. X.IP "o or O"
  1686. XThis causes the number to be interpreted as octal. ie. 377o
  1687. X.RE
  1688. X
  1689. X.IP "-"
  1690. XA character constant can be entered as 'c' where c is some
  1691. Xcharacter. \\b, \\n, \\r, \\t, \\' \\0 are also valid. A character
  1692. Xconstant can be used anywhere that an integer value can.
  1693. X
  1694. X.IP "-"
  1695. XA string is entered as a set of characters enclosed in double quotes "".
  1696. XA string is only valid with the .BYTE directive. \\b, \\n, \\r, \\t, \\"
  1697. Xare also valid escapes. However \\0 is not.
  1698. X
  1699. X.IP "-"
  1700. XInstructions, directives, and the symbols: R0, R1, R2, R3, R4, R5,
  1701. XR6, R7, A, AB, and C can be entered in upper or lower case without
  1702. Xassembler confusion. These words however cannot be defined as a user symbol.
  1703. XAny user symbol may be used, and case will be preserved. So the
  1704. Xuser symbols "foo" and "Foo" are different, but "addc" is the same
  1705. Xas "aDdC".
  1706. X
  1707. X.IP "-"
  1708. XA symbol can be any alpha numerical character plus the underscore ('_').
  1709. X
  1710. X.IP "-"
  1711. XExpressions are accepted in most places where a value or a symbol is
  1712. Xneeded. An expression consists of the following operators. All
  1713. Xoperators evaulate to integer objects (higher precedence opertors listed
  1714. Xfirst):
  1715. X.RS
  1716. X.IP "-"
  1717. XUnary minus
  1718. X.IP "&"
  1719. XBit-wise AND.
  1720. X.IP "|"
  1721. XBit-Wise OR.
  1722. X.IP "*"
  1723. XInteger multiplication.
  1724. X.IP
  1725. X\\ Integer division
  1726. X.IP "%"
  1727. XIntieger modulus
  1728. X.IP "+"
  1729. XInteger addition.
  1730. X.IP "-"
  1731. XInteger subtraction.
  1732. X.RE
  1733. X.IP "-"
  1734. XIn addition to these operators, a special symbol '*' may be used
  1735. Xto represent the current location counter.
  1736. X
  1737. X.SH EXAMPLES
  1738. X.IP
  1739. XBelow is a sample assembly program.
  1740. X.RS
  1741. X.nf
  1742. X
  1743. X                .org    0
  1744. Xstart:          mov     P3, #0xff       ; use alternate fns on P3
  1745. X                            ; leds on P1 are inverted.
  1746. X                setb    F0              ; climbing up
  1747. X                mov     A, #0x01        ; initial bit
  1748. X
  1749. Xwrite:          cpl     A               ; write it
  1750. X                mov     P1, A
  1751. X                cpl     A
  1752. X                acall   delay
  1753. X                jb      F0, climbup     ; climbing which way?
  1754. X
  1755. Xclimbdn:        rr      A               ; down - shift right
  1756. X                jnb     ACC.0, write    ; back for more
  1757. X                setb    F0
  1758. X                ajmp    write
  1759. X
  1760. Xclimbup:        rl      A               ; up - shift left
  1761. X                jnb     ACC.7, write    ; back for more
  1762. X                clr     F0
  1763. X                ajmp    write
  1764. X                .end            ; this directive ignored.
  1765. X.fi
  1766. X
  1767. X
  1768. X.SH AUTHOR
  1769. XKen Stauffer (University of Calgary)
  1770. X.br
  1771. Xstauffer@cpsc.ucalgary.ca
  1772. END_OF_FILE
  1773. if test 9374 -ne `wc -c <'as31.man'`; then
  1774.     echo shar: \"'as31.man'\" unpacked with wrong size!
  1775. fi
  1776. # end of 'as31.man'
  1777. fi
  1778. if test -f 'emitter.c' -a "${1}" != "-c" ; then 
  1779.   echo shar: Will not clobber existing file \"'emitter.c'\"
  1780. else
  1781. echo shar: Extracting \"'emitter.c'\" \(8382 characters\)
  1782. sed "s/^X//" >'emitter.c' <<'END_OF_FILE'
  1783. X/* ----------------------------------------------------------------------
  1784. X * FILE: emitter.c
  1785. X * PACKAGE: as31 - 8031/8051 Assembler.
  1786. X *
  1787. X * DESCRIPTION:
  1788. X *    This file contains the code to generate various
  1789. X *    object code formats. Provisions exist to
  1790. X *    support many types of output formats within the
  1791. X *    same executable.
  1792. X *
  1793. X * REVISION HISTORY:
  1794. X *    Jan. 19, 1990 - Created. (Ken Stauffer)
  1795. X *    Jan. 29, 1990 - Added S-records (Theo Deraadt)
  1796. X *
  1797. X *
  1798. X * AUTHOR:
  1799. X *    All code in this file written by Ken Stauffer (University of Calgary).
  1800. X *    January, 1990.
  1801. X */
  1802. X
  1803. X#include <stdio.h>
  1804. X
  1805. X/* ----------------------------------------------------------------------
  1806. X * DECLARE your own open(), close(), addr(), and byte() routines here.
  1807. X *
  1808. X */
  1809. X
  1810. Xstatic int open1(), close1(), addr1(), byte1();
  1811. Xstatic int open2(), close2(), addr2(), byte2();
  1812. Xstatic int open3(), close3(), addr3(), byte3();
  1813. Xstatic int open4(), close4(), addr4(), byte4();
  1814. X
  1815. X/* ----------------------------------------------------------------------
  1816. X * ADD an entry to this table to register your
  1817. X * output format routines. Give your object format
  1818. X * a name to be specified with the -F option.
  1819. X *
  1820. X */
  1821. X
  1822. Xstatic int format;
  1823. Xstatic struct {
  1824. X    char *name;
  1825. X    int (*e_open)();
  1826. X    int (*e_close)();
  1827. X    int (*e_addr)();
  1828. X    int (*e_byte)();
  1829. X} formtab[] = {
  1830. X    { "tdr",   open1, close1, addr1, byte1 },
  1831. X    { "byte",  open2, close2, addr2, byte2 },
  1832. X    { "od",    open3, close3, addr3, byte3 },
  1833. X    { "srec2", open4, close4, addr4, byte4 },
  1834. X    { "srec3", open4, close4, addr4, byte4 },
  1835. X    { "srec4", open4, close4, addr4, byte4 }
  1836. X};
  1837. X
  1838. X#define FORMTABSIZE    (sizeof(formtab)/sizeof(formtab[0]))
  1839. X
  1840. Xemitusage()
  1841. X{
  1842. X    int i;
  1843. X    fprintf(stderr, "\tfmt is one of:");
  1844. X    for(i=0; i<FORMTABSIZE; ) {
  1845. X        fprintf(stderr, "%s", formtab[i].name);
  1846. X        if( ++i < FORMTABSIZE)
  1847. X            fprintf(stderr, ", ");
  1848. X    }
  1849. X    fprintf(stderr, ".\n");
  1850. X}
  1851. X
  1852. Xemitopen(file,ftype,arg)
  1853. Xchar *file,*ftype,*arg;
  1854. X{
  1855. X    int i;
  1856. X    if( ftype ) {
  1857. X        for(i=0; i<FORMTABSIZE; i++ ) {
  1858. X            if( !strcmp(formtab[i].name,ftype) ) {
  1859. X                format = i;
  1860. X                (*formtab[format].e_open)(file,ftype,arg);
  1861. X                return;
  1862. X            }
  1863. X        }
  1864. X        fprintf(stderr, "warning: no format \"%s\", using \"%s\"\n",
  1865. X            ftype, formtab[0].name);
  1866. X    }
  1867. X    /*
  1868. X     * 0th entry is the default format type
  1869. X     */
  1870. X    format = 0;
  1871. X    (*formtab[format].e_open)(file,ftype,arg);
  1872. X}
  1873. X
  1874. Xemitclose()
  1875. X{
  1876. X    (*formtab[format].e_close)();
  1877. X}
  1878. X
  1879. Xemitaddr(a)
  1880. Xunsigned long int a;
  1881. X{
  1882. X    (*formtab[format].e_addr)(a);
  1883. X}
  1884. X
  1885. Xemitbyte(b)
  1886. Xint b;
  1887. X{
  1888. X    (*formtab[format].e_byte)(b);
  1889. X}
  1890. X
  1891. X/* ----------------------------------------------------------------------
  1892. X * Individual file format routines appear here:
  1893. X *    Each file format must define the following routines:
  1894. X *        open()    - Called ONCE before any of the others.
  1895. X *            It is passed with a filename and a format
  1896. X *            specific argument.
  1897. X *
  1898. X *        close() - Called ONCE when no more emit_byte()
  1899. X *            function calls will be made.
  1900. X *
  1901. X *        addr() - Called when ever a new address has been set
  1902. X *            in the assembler (ie. .org, .skip).
  1903. X *            This routine is also called once when the
  1904. X *            location counter is set to 0 at the very start of
  1905. X *            assembling.
  1906. X * 
  1907. X *        byte() - Called with each byte to be outputed.
  1908. X *
  1909. X */
  1910. X
  1911. X/* ----------------------------------------------------------------------
  1912. X * "tdr" format. For tdr's 68008 system. Generates a
  1913. X * script file readable by a debugger.
  1914. X *    [addr] : [byte] [byte] ..
  1915. X *
  1916. X * arg: This is a number in decimal which specifies
  1917. X *    the offset, -Ftdr -A0000
  1918. X *
  1919. X *    These options specifies the tdr format, with an argument
  1920. X *    of 0. This becomes the offset used in generating the
  1921. X *    script file. The default if no A is present is 0x10000.
  1922. X * 
  1923. X */
  1924. X
  1925. Xstatic unsigned long addr;
  1926. Xstatic FILE *fout;
  1927. Xstatic long int offset;
  1928. Xstatic int newaddr;
  1929. Xstatic int pos=-666;
  1930. X
  1931. Xstatic open1(file,ftype,arg)
  1932. Xchar *file, *ftype, *arg;
  1933. X{
  1934. X    fout = fopen(file,"w");
  1935. X    if( fout == NULL ) {
  1936. X        fprintf(stderr,"Cannot open %s for writting.\n",file);
  1937. X        exit(1);
  1938. X    }
  1939. X    if( arg ) {
  1940. X        offset = atoi(arg);
  1941. X    } else
  1942. X        offset = 0x10000;
  1943. X}
  1944. X
  1945. Xstatic close1()
  1946. X{
  1947. X    if( pos != 15 ) fprintf(fout,"\n");
  1948. X    fclose(fout);
  1949. X}
  1950. X
  1951. Xstatic addr1(a)
  1952. Xunsigned long int a;
  1953. X{
  1954. X    addr = a;
  1955. X    newaddr = 1;
  1956. X}
  1957. X
  1958. Xstatic byte1(b)
  1959. Xunsigned char b;
  1960. X{
  1961. X    if( newaddr ) {
  1962. X        if( pos != -666 ) fprintf(fout,"\n");
  1963. X        newaddr = 0;
  1964. X        pos = 15;
  1965. X        fprintf(fout,"%06x: ",addr+offset);
  1966. X    } else if( pos == 15 ) {
  1967. X        fprintf(fout,"%06x: ",addr+offset);
  1968. X    }
  1969. X
  1970. X    fprintf(fout,"%02x ", b&0xff );
  1971. X
  1972. X    if( pos-- == 0 ) {
  1973. X        fprintf(fout,"\n");
  1974. X        pos = 15;
  1975. X    }
  1976. X    addr += 1;
  1977. X}
  1978. X
  1979. X
  1980. X/* ----------------------------------------------------------------------
  1981. X * "byte" format.
  1982. X *    Like "tdr" but each byte is on a line by itself.
  1983. X *    This is nice for debugging. No -A is used.
  1984. X */
  1985. X
  1986. Xstatic open2(file,ftype,arg)
  1987. Xchar *file, *ftype, *arg;
  1988. X{
  1989. X    fout = fopen(file,"w");
  1990. X    if( fout == NULL ) {
  1991. X        fprintf(stderr,"Cannot open %s for writting.\n",file);
  1992. X        exit(1);
  1993. X    }
  1994. X}
  1995. X
  1996. Xstatic close2()
  1997. X{
  1998. X    fclose(fout);
  1999. X}
  2000. X
  2001. Xstatic addr2(a)
  2002. Xunsigned long int a;
  2003. X{
  2004. X    addr = a;
  2005. X}
  2006. X
  2007. Xstatic byte2(b)
  2008. Xunsigned char b;
  2009. X{
  2010. X    fprintf(fout,"%04x: %02x\n", addr, b&0xff );
  2011. X    addr += 1;
  2012. X}
  2013. X
  2014. X
  2015. X/* ----------------------------------------------------------------------
  2016. X * "od", this format shows 16 bytes per line, with address.
  2017. X *    It also includes ascii on one side.
  2018. X *
  2019. X * The format is similar to the od(1) program under Unix.
  2020. X *
  2021. X */
  2022. X
  2023. Xstatic int pos3;
  2024. Xstatic unsigned char buf[16];
  2025. Xstatic unsigned long saveaddr;
  2026. X
  2027. Xstatic open3(file,ftype,arg)
  2028. Xchar *file, *arg;
  2029. X{
  2030. X    fout = fopen(file,"w");
  2031. X    if( fout == NULL ) {
  2032. X        fprintf(stderr,"Cannot open %s for writting.\n",file);
  2033. X        exit(1);
  2034. X    }
  2035. X}
  2036. X
  2037. Xstatic close3()
  2038. X{
  2039. X    dumpline(saveaddr,buf,pos3-1);
  2040. X    fclose(fout);
  2041. X}
  2042. X
  2043. Xstatic addr3(a)
  2044. Xunsigned long int a;
  2045. X{
  2046. X    newaddr = 1;
  2047. X    addr = a;
  2048. X}
  2049. X
  2050. Xstatic byte3(b)
  2051. Xunsigned char b;
  2052. X{
  2053. X    if( newaddr ) {
  2054. X        dumpline(saveaddr,buf,pos3-1);
  2055. X        pos3 = 0;
  2056. X        newaddr = 0;
  2057. X        saveaddr = addr;
  2058. X    } else if( pos3 == 16 ) {
  2059. X        dumpline(saveaddr,buf,pos3-1);
  2060. X        pos3 = 0;
  2061. X        saveaddr = addr;
  2062. X    }
  2063. X    buf[pos3++] = b & 0x00ff;
  2064. X
  2065. X    addr += 1;
  2066. X}
  2067. X
  2068. Xdumpline(a,b,len)
  2069. Xunsigned long a;
  2070. Xunsigned char *b;
  2071. Xint len;
  2072. X{
  2073. X    int i;
  2074. X
  2075. X    if(len <= 0 ) return;
  2076. X
  2077. X    fprintf(fout,"%04x: ",a);
  2078. X
  2079. X    for(i=0; i<8; i++ ) {
  2080. X        if( i <= len )
  2081. X            fprintf(fout,"%02x ",b[i]);
  2082. X        else
  2083. X            fprintf(fout,"   ");
  2084. X    }
  2085. X
  2086. X    fprintf(fout,"- ");
  2087. X
  2088. X    for(i=8; i<16; i++ ) {
  2089. X        if( i <= len )
  2090. X            fprintf(fout,"%02x ",b[i]);
  2091. X        else
  2092. X            fprintf(fout,"   ");
  2093. X    }
  2094. X    fprintf(fout,"   ");
  2095. X
  2096. X    for(i=0; i<16; i++ ) {
  2097. X        if( i <= len )
  2098. X            fprintf(fout,"%c",
  2099. X                (b[i]>=' ' && b[i]<='~') ? b[i] : '.' );
  2100. X        else
  2101. X            break;
  2102. X    }
  2103. X    fprintf(fout,"\n");
  2104. X}
  2105. X
  2106. X/* ----------------------------------------------------------------------
  2107. X * srecord format. This is called with "-Fsrec2", "-Fsrec3", or
  2108. X * "-Fsrec4"...
  2109. X *
  2110. X * arg: This is a number in decimal which specifies
  2111. X *    the offset, -Fsrec3 -A0000
  2112. X *
  2113. X *    These options specifies the tdr format, with an argument
  2114. X *    of 0. This becomes the offset used in generating the
  2115. X *    script file. The default if no A is present is 0x0000.
  2116. X * 
  2117. X */
  2118. X#define SREC_BYTESPERLINE 32
  2119. X
  2120. Xstatic char format4;
  2121. Xstatic int check4, index4;
  2122. Xstatic char buf4[SREC_BYTESPERLINE];
  2123. Xstatic long address4;
  2124. X
  2125. Xstatic open4(file,ftype,arg)
  2126. Xchar *file, *ftype, *arg;
  2127. X{
  2128. X    format4 = ftype[4];        /* will be '2' -- '4' */
  2129. X
  2130. X    fout = fopen(file,"w");
  2131. X    if( fout == NULL ) {
  2132. X        fprintf(stderr,"Cannot open %s for writing.\n",file);
  2133. X        exit(1);
  2134. X    }
  2135. X
  2136. X    if(arg)    offset = atoi(arg);
  2137. X    else    offset = 0;
  2138. X
  2139. X    fprintf(fout, "S0030000%02X\n", (~3 & 0xff) );
  2140. X
  2141. X}
  2142. X
  2143. Xstatic close4()
  2144. X{
  2145. X    if(index4)
  2146. X        finishline();
  2147. X    switch(format4) {
  2148. X    case '2':
  2149. X        fprintf(fout, "S9030000%02X\n", ~3 & 0xff);
  2150. X        break;
  2151. X    case '3':
  2152. X        fprintf(fout, "S804000000%02X\n", ~4 & 0xff);
  2153. X        break;
  2154. X    case '4':
  2155. X        fprintf(fout, "S70500000000%02X\n", ~5 & 0xff);
  2156. X        break;
  2157. X    }
  2158. X    fclose(fout);
  2159. X}
  2160. X
  2161. X
  2162. Xstatic addr4(a)
  2163. Xunsigned long int a;
  2164. X{
  2165. X    if(index4>0)
  2166. X        finishline();
  2167. X    address4 = a + offset;
  2168. X}
  2169. X
  2170. Xstatic byte4(b)
  2171. X{
  2172. X    buf4[index4++] = b;
  2173. X    if(index4==SREC_BYTESPERLINE) {
  2174. X        finishline();
  2175. X        address4 += SREC_BYTESPERLINE;
  2176. X    }
  2177. X}
  2178. X
  2179. Xfinishline()
  2180. X{
  2181. X    int i;
  2182. X
  2183. X    check4 = index4 + (address4 & 0xff) + ((address4>>8) & 0xff) + 4;
  2184. X
  2185. X    switch(format4) {
  2186. X    case '2':
  2187. X        fprintf(fout, "S1%02X%04X", index4 + 4,    address4 & 0xffff);
  2188. X        break;
  2189. X    case '3':
  2190. X        fprintf(fout, "S2%02X%06X", index4 + 6, address4 & 0xffffff);
  2191. X        check4 += ((address4>>16) & 0xff) + 2;
  2192. X        break;
  2193. X    case '4':
  2194. X        fprintf(fout, "S3%02X%08X", index4 + 8, address4);
  2195. X        check4 += ((address4>>16) & 0xff) +((address4>>24) & 0xff) + 4;
  2196. X        break;
  2197. X    }
  2198. X
  2199. X    for(i=0; i<index4; i++) {
  2200. X        fprintf(fout, "%02X", buf4[i] & 0xff);
  2201. X        check4 += buf4[i];
  2202. X    }
  2203. X
  2204. X    fprintf(fout, "%02X\n", (~check4 & 0xff) );
  2205. X    index4 = 0;
  2206. X}
  2207. X
  2208. END_OF_FILE
  2209. if test 8382 -ne `wc -c <'emitter.c'`; then
  2210.     echo shar: \"'emitter.c'\" unpacked with wrong size!
  2211. fi
  2212. # end of 'emitter.c'
  2213. fi
  2214. if test -f 'lexer.c' -a "${1}" != "-c" ; then 
  2215.   echo shar: Will not clobber existing file \"'lexer.c'\"
  2216. else
  2217. echo shar: Extracting \"'lexer.c'\" \(6816 characters\)
  2218. sed "s/^X//" >'lexer.c' <<'END_OF_FILE'
  2219. X/* ----------------------------------------------------------------------
  2220. X * FILE: lexer.c
  2221. X * PACKAGE: as31 - 8031/8051 Assembler.
  2222. X *
  2223. X * DESCRIPTION:
  2224. X *    This file contains the lexical tokenizer for the assembler.
  2225. X *    Since yacc is being used the lexer is called yylex().
  2226. X *
  2227. X *    In order to produce a listing, some record of the users
  2228. X *    source line must be kept. This is done by adding
  2229. X *    get_ch(), and unget_ch() routine which returns/ungets a character
  2230. X *    but also places information into a secret array.
  2231. X *
  2232. X *    When a newline is encountered the text line is returned as
  2233. X *    an attribute on the '\n' character.
  2234. X *
  2235. X * REVISION HISTORY:
  2236. X *    Jan. 19, 1990 - Created. (Ken Stauffer)
  2237. X *
  2238. X * AUTHOR:
  2239. X *    All code in this file written by Ken Stauffer (University of Calgary).
  2240. X *    January, 1990.
  2241. X *
  2242. X */
  2243. X
  2244. X#include <stdio.h>
  2245. X#include <ctype.h>
  2246. X#include "as31.h"
  2247. X
  2248. Xextern union ystack yylval;
  2249. Xextern int pass;
  2250. X
  2251. Xstruct symbol *looksym();
  2252. Xstruct opcode *lookop();
  2253. Xchar *malloc();
  2254. Xint lineno;
  2255. X
  2256. Xstatic char line[100],*lineptr=line;
  2257. X
  2258. X/* ----------------------------------------------------------------------
  2259. X * get_ch:
  2260. X *    Get a character from stdin, place char in line[]
  2261. X */
  2262. X
  2263. Xget_ch()
  2264. X{
  2265. X    register int c;
  2266. X
  2267. X    c = getchar();
  2268. X    if( c != EOF && lineptr - line < sizeof(line) )
  2269. X        *lineptr++ = c;
  2270. X    return(c);
  2271. X}
  2272. X
  2273. X/* ----------------------------------------------------------------------
  2274. X * unget_ch:
  2275. X *    Unget a character and move lineptr back by one.
  2276. X */
  2277. X
  2278. Xunget_ch(c)
  2279. Xint c;
  2280. X{
  2281. X    ungetc(c,stdin);
  2282. X    if( lineptr > line )
  2283. X        lineptr--;
  2284. X}
  2285. X
  2286. X/* ----------------------------------------------------------------------
  2287. X * yylex:
  2288. X *    The tokens themselves are returned via return(token)
  2289. X *
  2290. X *    Some tokens have attributes. These attributes are returned
  2291. X *    by setting a global variable yylval:
  2292. X *
  2293. X *        yylval.value
  2294. X *            numbers (any base)
  2295. X *            strings (in pass 1).
  2296. X *            bit positions .0, .1, .2, ...
  2297. X *
  2298. X *        yylval.str
  2299. X *            strings (in pass 2).
  2300. X *            '\n' (both passes).
  2301. X *
  2302. X *        yylval.sym
  2303. X *            User defined symbols.
  2304. X *
  2305. X *        yylval.op
  2306. X *            Reserved keyword (opcode/directive/misc.)
  2307. X *
  2308. X *        No other fields in yylval are used by yylex().
  2309. X * 
  2310. X *        Characters that do not have an attribute do
  2311. X *        not set anything in the yylval variable.
  2312. X *
  2313. X */
  2314. X
  2315. Xyylex()
  2316. X{
  2317. X    static nl_flag=0;    /* sync. error messages and the cur. line */
  2318. X    register int c;
  2319. X    char buf[120];        /* temporary buffer */
  2320. X    char *p;        /* general pointer */
  2321. X    struct symbol *sym;
  2322. X    struct opcode *op;
  2323. X
  2324. X    int octal=0,hex=0,decimal=0,binary=0;
  2325. X    register long value = 0;
  2326. X
  2327. X    if( nl_flag ) {
  2328. X        nl_flag = 0;
  2329. X        lineno++;
  2330. X    }
  2331. X
  2332. Xfor(;;) {
  2333. X    c = get_ch();
  2334. X    switch(c) {
  2335. X    case EOF: return(EOF);
  2336. X    case ' ':
  2337. X    case '\t':
  2338. X        break;
  2339. X
  2340. X    case '\n':
  2341. X        nl_flag = 1;
  2342. X        yylval.str = line;
  2343. X        *lineptr = '\0';
  2344. X        lineptr = line;
  2345. X        return('\n');
  2346. X
  2347. X    case ';':
  2348. X        while((c=get_ch()) != EOF && c!='\n');
  2349. X        nl_flag= 1;
  2350. X        yylval.str = line;
  2351. X        *lineptr = '\0';
  2352. X        lineptr = line;
  2353. X        return(c);
  2354. X
  2355. X    case '"':
  2356. X        p = buf;
  2357. X        while((c=get_ch()) != EOF && c!='"' && c!='\n') {
  2358. X            if( c == '\\' ) {
  2359. X                switch(c=get_ch()) {
  2360. X                case 'n': c = '\n'; break;
  2361. X                case 'r': c = '\r'; break;
  2362. X                case 't': c = '\t'; break;
  2363. X                case 'b': c = '\b'; break;
  2364. X                case '"': c = '"'; break;
  2365. X                case '\\': c = '\\'; break;
  2366. X                default:
  2367. X                  error("Invalid escape character: \\%c",c);
  2368. X                  break;
  2369. X                }
  2370. X            }
  2371. X            if( p-buf<sizeof(buf)-1 ) 
  2372. X                *p++ = c;
  2373. X            else {
  2374. X               error("String constant longer than %d bytes",
  2375. X                    sizeof(buf));
  2376. X            }
  2377. X        }
  2378. X        *p = '\0';
  2379. X        if( c == '\n' || c == EOF ) {
  2380. X            error("String terminated improperly.");
  2381. X            unget_ch(c);
  2382. X        }
  2383. X
  2384. X        if(pass1)
  2385. X            yylval.value = strlen(buf);
  2386. X        else {
  2387. X            if( (p = malloc(strlen(buf)+1)) == NULL )
  2388. X               error("Cannot allocate %d bytes",strlen(buf)+1);
  2389. X            strcpy(p,buf);
  2390. X            yylval.str = p;
  2391. X        }
  2392. X        return(STRING);
  2393. X
  2394. X    case '.':
  2395. X        if( (c=get_ch())>='0' && c<='7' ) {
  2396. X            yylval.value = c-'0';
  2397. X            return(BITPOS);
  2398. X        }
  2399. X        unget_ch(c);
  2400. X        return('.');
  2401. X
  2402. X    case '\'':
  2403. X        c = get_ch();
  2404. X        if( c=='\\' ) {
  2405. X            switch(c=get_ch()) {
  2406. X            case 'n': c = '\n'; break;
  2407. X            case 'r': c = '\r'; break;
  2408. X            case 't': c = '\t'; break;
  2409. X            case 'b': c = '\b'; break;
  2410. X            case '\\': c = '\\'; break;
  2411. X            case '\'': c = '\''; break;
  2412. X            default:
  2413. X                error("Invalid escape character: \\%c",c);
  2414. X            }
  2415. X        }
  2416. X        if( get_ch() != '\'' )
  2417. X            error("Missing quote in character constant");
  2418. X        yylval.value = c;
  2419. X        return(VALUE);
  2420. X
  2421. X    case '0':    /* parse a number            */
  2422. X    case '1':    /* could be followed by a:        */
  2423. X    case '2':    /*    'b','B' - Binary        */
  2424. X    case '3':    /*    'h','H' - Hex            */
  2425. X    case '4':    /*    'd','D' - Decimal        */
  2426. X    case '5':    /*    'o','O' - Octal            */
  2427. X    case '6':    /* *** Numbers must start with a digit    */
  2428. X    case '7':    /* Numbers could be also preceeded by:  */
  2429. X    case '8':    /*    0x    - Hex,    0b     - binary */
  2430. X    case '9':    /*    0    - Octal            */
  2431. X
  2432. X        p = buf;
  2433. X        do {
  2434. X            if( p-buf<sizeof(buf)-1 )
  2435. X                *p++ = c;
  2436. X            c = get_ch();
  2437. X        } while( c=='H' || c=='h' || c=='O' || c=='o' ||
  2438. X                c=='x' || c=='X' || isxdigit(c) );
  2439. X        unget_ch(c);
  2440. X        *p = '\0';
  2441. X
  2442. X
  2443. X        /* Check any preceeding chars */
  2444. X        if( buf[0]=='0' && (buf[1]=='x' || buf[1]=='X') ) {
  2445. X                hex++;
  2446. X                buf[1] = '0';
  2447. X        } else if( buf[0]=='0' &&
  2448. X            (buf[1]=='b' || buf[1]=='B') ) {
  2449. X                binary++;
  2450. X                buf[1] = '0';
  2451. X            }
  2452. X        else if( buf[0]=='0' ) octal++;
  2453. X
  2454. X        /* check any trailing chars */
  2455. X        c = *(p-1);
  2456. X        if( !hex && (c=='b' || c=='B') )
  2457. X            { binary++; *(p-1) = '\0'; }
  2458. X        else if( c=='H' || c=='h' )
  2459. X            { hex++; *(p-1) = '\0'; }
  2460. X        else if( !hex && (c=='D' || c=='d') )
  2461. X            { decimal++; *(p-1) = '\0'; }
  2462. X        else if( c=='O' || c=='o' )
  2463. X            { octal++; *(p-1) = '\0'; }
  2464. X        else if( !hex && !octal && !binary) decimal++;
  2465. X
  2466. X        if( binary ) {
  2467. X            for(p=buf; *p; p++ ) {
  2468. X                if( *p=='1' ) value = value<<1 + 1;
  2469. X                else if( *p=='0' ) value = value<<1;
  2470. X                else
  2471. X                  error("Invalid binary digit: %c",*p);
  2472. X            }
  2473. X            yylval.value = value;
  2474. X            return(VALUE);
  2475. X        }
  2476. X
  2477. X        if( hex ) {
  2478. X            for(p=buf; *p; p++ ) {
  2479. X                value <<= 4;
  2480. X                if( isdigit(*p) )
  2481. X                    value += *p-'0';
  2482. X                else if( *p>='a' && *p<='f' )
  2483. X                    value += *p-'a'+ 10;
  2484. X                else if( *p>='A' && *p<='F' )
  2485. X                    value += *p-'A'+ 10;
  2486. X                else
  2487. X                  error("Invalid hex digit: %c",*p);
  2488. X            }
  2489. X            yylval.value = value;
  2490. X            return(VALUE);
  2491. X        }
  2492. X
  2493. X        if( decimal ) {
  2494. X            for(p=buf; *p; p++ ) {
  2495. X                if( isdigit(*p) )
  2496. X                    value = value*10 + *p-'0';
  2497. X                else
  2498. X                   error("Invalid decimal digit: %c",*p);
  2499. X            }
  2500. X            yylval.value = value;
  2501. X            return(VALUE);
  2502. X        }
  2503. X
  2504. X        if( octal ) {
  2505. X            for(p=buf; *p; p++ ) {
  2506. X                if( *p>='0' && *p<='7' )
  2507. X                    value = value<<3 + *p-'0';
  2508. X                else
  2509. X                   error("Invalid octal digit: %c",*p);
  2510. X            }
  2511. X            yylval.value = value;
  2512. X            return(VALUE);
  2513. X        }
  2514. X
  2515. X    default:
  2516. X        if( isalpha(c) || c=='_' ) {
  2517. X            p = buf;
  2518. X            do {
  2519. X                if( p-buf<sizeof(buf)-1 )
  2520. X                    *p++ = c;
  2521. X                c = get_ch();
  2522. X            } while( isalnum(c) || c=='_' );
  2523. X            *p = '\0';
  2524. X            unget_ch(c);
  2525. X            if( op = lookop(buf) ) {
  2526. X                yylval.op = op;
  2527. X                return(op->type);
  2528. X            }
  2529. X            sym = looksym(buf);
  2530. X            yylval.sym = sym;
  2531. X            return(SYMBOL);
  2532. X        } else
  2533. X            return(c);
  2534. X    } /* switch */
  2535. X} /* for */
  2536. X
  2537. X} /* yylex */
  2538. END_OF_FILE
  2539. if test 6816 -ne `wc -c <'lexer.c'`; then
  2540.     echo shar: \"'lexer.c'\" unpacked with wrong size!
  2541. fi
  2542. # end of 'lexer.c'
  2543. fi
  2544. if test -f 'main.c' -a "${1}" != "-c" ; then 
  2545.   echo shar: Will not clobber existing file \"'main.c'\"
  2546. else
  2547. echo shar: Extracting \"'main.c'\" \(2745 characters\)
  2548. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  2549. X/* ----------------------------------------------------------------------
  2550. X * FILE: main.c
  2551. X * PACKAGE: as31 - 8031/8051 Assembler.
  2552. X *
  2553. X * DESCRIPTION:
  2554. X *    The file contains main(). It handles the arguments and makes
  2555. X *    sure that pass 1 is done before pass 2 etc...
  2556. X *
  2557. X * REVISION HISTORY:
  2558. X *    Jan. 19, 1990 - Created. (Ken Stauffer)
  2559. X *
  2560. X * AUTHOR:
  2561. X *    All code in this file written by Ken Stauffer (University of Calgary).
  2562. X *    January, 1990. */ static char
  2563. X *    id_id= "Written by: Ken Stauffer";/*
  2564. X *
  2565. X */
  2566. X
  2567. X#include <stdio.h>
  2568. X#include <setjmp.h>
  2569. X
  2570. Xextern int lineno;
  2571. Xextern int pass,fatal;
  2572. Xextern unsigned long lc;
  2573. X
  2574. Xjmp_buf main_env;
  2575. Xchar *asmfile;
  2576. Xint dashl=0;
  2577. XFILE *listing;
  2578. X
  2579. X/* ----------------------------------------------------------------------
  2580. X * checkext:
  2581. X *    Check the string s, for the presence of an extenstion e.
  2582. X *    Return the position of the start of e in s.
  2583. X *    or return NULL.
  2584. X */
  2585. X
  2586. Xchar *checkext(s,e)
  2587. Xchar *s,*e;
  2588. X{
  2589. X    register char *ps = s, *pe = e;
  2590. X
  2591. X    while( *ps ) ps++;
  2592. X    while( *pe ) pe++;
  2593. X
  2594. X    for( ; ps>=s && pe>=e && *ps == *pe; ps--, pe-- )
  2595. X        if( pe == e ) return(ps);
  2596. X    return(NULL);
  2597. X}
  2598. X
  2599. Xmain(argc,argv)
  2600. Xchar *argv[];
  2601. X{
  2602. X    FILE *fin;
  2603. X    char *p,*dashF=NULL, *dashA=NULL;
  2604. X    char objfile[100];
  2605. X    char lstfile[100];
  2606. X    int i;
  2607. X
  2608. X    if( argc < 2 ) {
  2609. X        fprintf(stderr,"Usage: %s [-l] [-Ffmt] [-Aarg] infile.asm\n",
  2610. X                        argv[0]);
  2611. X        emitusage();
  2612. X        exit(1);
  2613. X    }
  2614. X
  2615. X    for(i=1; i<argc; i++ ) {
  2616. X        if( argv[i][0] != '-' ) break;
  2617. X        if( argv[i][1] == 'l' ) dashl = 1;
  2618. X        else if( dashF == NULL && argv[i][1] == 'F' )
  2619. X            dashF = argv[i]+2;
  2620. X        else if( dashA == NULL && argv[i][1] == 'A' )
  2621. X            dashA = argv[i]+2;
  2622. X        else {
  2623. X            fprintf(stderr,"Duplicate or unknown flag.\n");
  2624. X            exit(1);
  2625. X        }
  2626. X    }
  2627. X    if( i == argc ) {
  2628. X        fprintf(stderr,"Missing input file.\n");
  2629. X        exit(1);
  2630. X    }
  2631. X
  2632. X    if( (p=checkext(argv[i],".asm")) == NULL ) {
  2633. X        fprintf(stderr,"Input file \"%s\" must end with .asm\n",
  2634. X                argv[i]);
  2635. X        exit(1);
  2636. X    }
  2637. X    asmfile = argv[i];
  2638. X
  2639. X    if( (fin = freopen(argv[i],"r",stdin)) == NULL ) {
  2640. X        fprintf(stderr,"Cannot open input file: %s\n",argv[i]);
  2641. X        exit(1);
  2642. X    }
  2643. X
  2644. X    if( dashl ) {
  2645. X        strcpy(lstfile,argv[i]);
  2646. X        strcpy(lstfile+(p-argv[i]),".lst");
  2647. X        listing = fopen(lstfile,"w");
  2648. X        if( listing == NULL ) {
  2649. X            fprintf(stderr,"Cannot open file: %s for writting.\n",
  2650. X                lstfile);
  2651. X            exit(1);
  2652. X        }
  2653. X    }
  2654. X    strcpy(objfile,argv[i]);
  2655. X    strcpy(objfile+(p-argv[i]),".obj");
  2656. X
  2657. X    emitopen(objfile,dashF,dashA);
  2658. X
  2659. X    syminit();
  2660. X    fatal = 0;
  2661. X    lineno = 1;
  2662. X    pass=0;
  2663. X    lc = 0x0000;
  2664. X
  2665. X    if( setjmp(main_env) ) {
  2666. X        fclose(fin);
  2667. X        emitclose();
  2668. X        unlink(objfile);
  2669. X        exit(1);
  2670. X    }
  2671. X
  2672. X    /*
  2673. X    ** P A S S    1
  2674. X    */
  2675. X    yyparse();
  2676. X    if( fatal ) longjmp(main_env,1);
  2677. X
  2678. X    rewind(fin);
  2679. X    lineno = 1;
  2680. X    pass++;
  2681. X    lc = 0x0000;
  2682. X    emitaddr(lc);
  2683. X
  2684. X    /*
  2685. X    ** P A S S    2
  2686. X    */
  2687. X    yyparse();
  2688. X
  2689. X    emitclose();
  2690. X    fclose(fin);
  2691. X    if( dashl )
  2692. X        fclose(listing);
  2693. X    exit(0);
  2694. X
  2695. X}
  2696. END_OF_FILE
  2697. if test 2745 -ne `wc -c <'main.c'`; then
  2698.     echo shar: \"'main.c'\" unpacked with wrong size!
  2699. fi
  2700. # end of 'main.c'
  2701. fi
  2702. if test -f 'makefile' -a "${1}" != "-c" ; then 
  2703.   echo shar: Will not clobber existing file \"'makefile'\"
  2704. else
  2705. echo shar: Extracting \"'makefile'\" \(856 characters\)
  2706. sed "s/^X//" >'makefile' <<'END_OF_FILE'
  2707. X# FILE: makefile
  2708. X# PACKAGE: as31 - 8031/8051 Assembler.
  2709. X#
  2710. X# DESCRIPTION:
  2711. X#
  2712. X#
  2713. X# REVISION HISTORY:
  2714. X#        Jan. 19, 1990 - Created. (Ken Stauffer).
  2715. X#        Jan. 30, 1990 - Theo played here.
  2716. X
  2717. XCFLAGS=-O
  2718. XYACCFLAGS=-d
  2719. XOBJ=as31.o symbol.o lexer.o emitter.o main.o
  2720. XSHARFILES=README as31.h as31.y as31.man emitter.c lexer.c main.c makefile \
  2721. X        symbol.c new.asm
  2722. X
  2723. Xas31:        $(OBJ)
  2724. X        $(CC) $(CFLAGS) -o as31 $(OBJ)
  2725. X        chmod a+rx as31
  2726. X
  2727. Xmain.o:        main.c as31.h
  2728. Xemitter.o:    emitter.c as31.h
  2729. Xsymbol.o:    symbol.c as31.h
  2730. Xlexer.o:    lexer.c as31.h
  2731. Xas31.o:        as31.c
  2732. Xas31.c:        as31.y as31.h
  2733. X        yacc $(YACCFLAGS) as31.y
  2734. X        /bin/mv y.tab.c as31.c
  2735. X
  2736. Xman:        as31.cat
  2737. X
  2738. Xas31.cat:    as31.man
  2739. X        nroff -man as31.man > as31.cat
  2740. X        chmod a+r as31.cat as31.man
  2741. X        
  2742. Xasm:        new.obj ram.obj
  2743. X
  2744. Xnew.obj:    new.asm
  2745. X        ./as31 -Ftdr -l new.asm
  2746. X
  2747. Xclean:
  2748. X        $(RM) *~ *.o as31.c y.tab.h as31.shar
  2749. X
  2750. Xshar:
  2751. X        shar $(SHARFILES) > as31.shar
  2752. END_OF_FILE
  2753. if test 856 -ne `wc -c <'makefile'`; then
  2754.     echo shar: \"'makefile'\" unpacked with wrong size!
  2755. fi
  2756. # end of 'makefile'
  2757. fi
  2758. if test -f 'symbol.c' -a "${1}" != "-c" ; then 
  2759.   echo shar: Will not clobber existing file \"'symbol.c'\"
  2760. else
  2761. echo shar: Extracting \"'symbol.c'\" \(10609 characters\)
  2762. sed "s/^X//" >'symbol.c' <<'END_OF_FILE'
  2763. X/* ----------------------------------------------------------------------
  2764. X * FILE: symbol.c
  2765. X * PACKAGE: as31 - 8031/8051 Assembler.
  2766. X *
  2767. X * DESCRIPTION:
  2768. X *    This file contains the symbol table search/insertion routines
  2769. X *    associated with user defined symbols.
  2770. X *
  2771. X *    The reserved keyword (instructions/directives) look up routine
  2772. X *    is defined here.
  2773. X *
  2774. X *    The opcode table for all of the instructions is located in this
  2775. X *    file.
  2776. X *
  2777. X * REVISION HISTORY:
  2778. X *    Jan. 19, 1990 - Created. (Ken Stauffer)
  2779. X *
  2780. X * AUTHOR:
  2781. X *    All code in this file written by Ken Stauffer (University of Calgary)
  2782. X *    January, 1990.
  2783. X *
  2784. X */
  2785. X
  2786. X#include "as31.h"
  2787. X#define NULL        (0)
  2788. X
  2789. X#define B(a)        (0xF0+(a))
  2790. X#define ACC(a)        (0xE0+(a))
  2791. X#define PSW(a)        (0xD0+(a))
  2792. X#define T2CON(a)    (0xC8+(a))
  2793. X#define IP(a)        (0xB8+(a))
  2794. X#define P3(a)        (0xB0+(a))
  2795. X#define IE(a)        (0xA8+(a))
  2796. X#define P2(a)        (0xA0+(a))
  2797. X#define SCON(a)        (0x98+(a))
  2798. X#define P1(a)        (0x90+(a))
  2799. X#define TCON(a)        (0x88+(a))
  2800. X#define P0(a)        (0x80+(a))
  2801. X
  2802. X/* ---------------------------------------------------------------------- 
  2803. X * sinit[]
  2804. X *    These symbols are not reserved keywords.
  2805. X *    This array contains the initial symbol table entries
  2806. X *    for the user symbol table. The symbols are
  2807. X *    basically convienient names that make writting
  2808. X *    in 8031/8051 bearable.
  2809. X *
  2810. X *    The function syminit() inserts these entries into the
  2811. X *    symbol table.
  2812. X *
  2813. X */
  2814. X
  2815. Xstatic struct symbol sinit[] = {
  2816. X    { "AC",        LABEL,        PSW(6),    NULL },
  2817. X    { "ACC",    LABEL,        ACC(0),    NULL },
  2818. X    { "B",        LABEL,        B(0),    NULL },
  2819. X    { "CY",        LABEL,        PSW(7),    NULL },
  2820. X    { "DPH",    LABEL,        0x83,    NULL },
  2821. X    { "DPL",    LABEL,        0x82,    NULL },
  2822. X    { "EA",        LABEL,        IE(7),    NULL },
  2823. X    { "ES",        LABEL,        IE(4),    NULL },
  2824. X    { "ET0",    LABEL,        IE(1),    NULL },
  2825. X    { "ET1",    LABEL,        IE(3),    NULL },
  2826. X    { "ET2",    LABEL,        IE(5),    NULL },
  2827. X    { "EX0",    LABEL,        IE(0),    NULL },
  2828. X    { "EX1",    LABEL,        IE(2),    NULL },
  2829. X    { "EXEN2",    LABEL,        T2CON(3),NULL },
  2830. X    { "EXF2",    LABEL,        T2CON(6),NULL },
  2831. X    { "F0",        LABEL,        PSW(5),    NULL },
  2832. X    { "IE",        LABEL,        IE(0),    NULL },
  2833. X    { "IE0",    LABEL,        TCON(1),NULL },
  2834. X    { "IE1",    LABEL,        TCON(3),NULL },
  2835. X    { "IP",        LABEL,        IP(0),    NULL },
  2836. X    { "IT0",    LABEL,        TCON(0),NULL },
  2837. X    { "IT1",    LABEL,        TCON(2),NULL },
  2838. X    { "OV",        LABEL,        PSW(2),    NULL },
  2839. X    { "P",        LABEL,        PSW(0),    NULL },
  2840. X    { "P0",        LABEL,        P0(0),    NULL },
  2841. X    { "P1",        LABEL,        P1(0),    NULL },
  2842. X    { "P2",        LABEL,        P2(0),    NULL },
  2843. X    { "P3",        LABEL,        P3(0),    NULL },
  2844. X    { "PCON",    LABEL,        0x87,    NULL },
  2845. X    { "PS",        LABEL,        IP(4),    NULL },
  2846. X    { "PSW",    LABEL,        PSW(0),    NULL },
  2847. X    { "PT0",    LABEL,        IP(1),    NULL },
  2848. X    { "PT1",    LABEL,        IP(3),    NULL },
  2849. X    { "PT2",    LABEL,        IP(5),    NULL },
  2850. X    { "PX0",    LABEL,        IP(0),    NULL },
  2851. X    { "PX1",    LABEL,        IP(2),    NULL },
  2852. X    { "RB8",    LABEL,        SCON(2),NULL },
  2853. X    { "RCAP2H",    LABEL,        0xCB,    NULL },
  2854. X    { "RCAP2L",    LABEL,        0xCA,    NULL },
  2855. X    { "RCLK",    LABEL,        T2CON(5),NULL },
  2856. X    { "REN",    LABEL,        SCON(4),NULL },
  2857. X    { "RI",        LABEL,        SCON(0),NULL },
  2858. X    { "RL2",    LABEL,        T2CON(0),NULL },
  2859. X    { "RS0",    LABEL,        PSW(3),    NULL },
  2860. X    { "RS1",    LABEL,        PSW(4),    NULL },
  2861. X    { "SBUF",    LABEL,        0x99,    NULL },
  2862. X    { "SCON",    LABEL,        SCON(0),NULL },
  2863. X    { "SM0",    LABEL,        SCON(7),NULL },
  2864. X    { "SM1",    LABEL,        SCON(6),NULL },
  2865. X    { "SM2",    LABEL,        SCON(5),NULL },
  2866. X    { "SP",        LABEL,        0x81,    NULL },
  2867. X    { "T2CON",    LABEL,        T2CON(0),NULL },
  2868. X    { "TB8",    LABEL,        SCON(3),NULL },
  2869. X    { "TCLK",    LABEL,        T2CON(4),NULL },
  2870. X    { "TCON",    LABEL,        TCON(0),NULL },
  2871. X    { "TF0",    LABEL,        TCON(5),NULL },
  2872. X    { "TF1",    LABEL,        TCON(7),NULL },
  2873. X    { "TF2",    LABEL,        T2CON(7),NULL },
  2874. X    { "TH0",    LABEL,        0x8C,    NULL },
  2875. X    { "TH1",    LABEL,        0x8D,    NULL },
  2876. X    { "TH2",    LABEL,        0xCD,    NULL },
  2877. X    { "TI",        LABEL,        SCON(1),NULL },
  2878. X    { "TL0",    LABEL,        0x8A,    NULL },
  2879. X    { "TL1",    LABEL,        0x8B,    NULL },
  2880. X    { "TL2",    LABEL,        0xCC,    NULL },
  2881. X    { "TMOD",    LABEL,        0x89,    NULL },
  2882. X    { "TR0",    LABEL,        TCON(4),NULL },
  2883. X    { "TR1",    LABEL,        TCON(6),NULL },
  2884. X    { "TR2",    LABEL,        T2CON(2),NULL }
  2885. X};
  2886. X
  2887. X#define SINITSIZE    (sizeof(sinit)/sizeof(sinit[0]))
  2888. X
  2889. X/* ----------------------------------------------------------------------
  2890. X * opcode vectors:
  2891. X *    These arrays contain the various opcodes for the
  2892. X *    various forms an instruction may take.
  2893. X *
  2894. X *    The ordering of these opcodes is very critical to the
  2895. X *    proper fuctioning of the assembler.
  2896. X *
  2897. X *    When a given form of an instruction is parsed, the parser
  2898. X *    indexes one of these arrays by the correct amount and thus
  2899. X *    obtains the correct opcode for the particular form.
  2900. X *
  2901. X */
  2902. X
  2903. Xstatic unsigned char acall[]=    { 0x11 };
  2904. Xstatic unsigned char add[]=    { 0x28, 0x25, 0x26, 0x24 };
  2905. Xstatic unsigned char addc[]=    { 0x38, 0x35, 0x36, 0x34 };
  2906. Xstatic unsigned char ajmp[]=    { 0x01 };
  2907. Xstatic unsigned char anl[]=    { 0x58, 0x55, 0x56, 0x54, 0x52, 0x53, 0x82,
  2908. X                  0xb0 };
  2909. Xstatic unsigned char cjne[]=    { 0xb5, 0xb4, 0xb8, 0xb6 };
  2910. Xstatic unsigned char clr[]=    { 0xe4, 0xc3, 0xc2 };
  2911. Xstatic unsigned char cpl[]=    { 0xf4, 0xb3, 0xb2 };
  2912. Xstatic unsigned char da[]=    { 0xd4 };
  2913. Xstatic unsigned char dec[]=    { 0x14, 0x18, 0x15, 0x16 };
  2914. Xstatic unsigned char div[]=    { 0x84 };
  2915. Xstatic unsigned char djnz[]=    { 0xd8, 0xd5 };
  2916. Xstatic unsigned char inc[]=    { 0x04, 0x08, 0x05, 0x06, 0xa3 };
  2917. Xstatic unsigned char jb[]=    { 0x20 };
  2918. Xstatic unsigned char jbc[]=    { 0x10 };
  2919. Xstatic unsigned char jc[]=    { 0x40 };
  2920. Xstatic unsigned char jmp[]=    { 0x73 };
  2921. Xstatic unsigned char jnb[]=    { 0x30 };
  2922. Xstatic unsigned char jnc[]=    { 0x50 };
  2923. Xstatic unsigned char jnz[]=    { 0x70 };
  2924. Xstatic unsigned char jz[]=    { 0x60 };
  2925. Xstatic unsigned char lcall[]=    { 0x12 };
  2926. Xstatic unsigned char ljmp[]=    { 0x02 };
  2927. Xstatic unsigned char mov[]=    { 0xe8, 0xe5, 0xe6, 0x74, 0xf5, 0x75, 0xf8,
  2928. X                  0xa8, 0x78, 0x88, 0x85, 0x86, 0xf6, 0xa6,
  2929. X                  0x76, 0x90, 0xa2, 0x92 };
  2930. Xstatic unsigned char movc[]=    { 0x93, 0x83 };
  2931. Xstatic unsigned char movx[]=    { 0xe2, 0xe3, 0xe0, 0xf2, 0xf3, 0xf0 };
  2932. Xstatic unsigned char mul[]=    { 0xa4 };
  2933. Xstatic unsigned char nop[]=    { 0x00 };
  2934. Xstatic unsigned char orl[]=    { 0x48, 0x45, 0x46, 0x44, 0x42, 0x43, 0x72,
  2935. X                  0xa0 };
  2936. Xstatic unsigned char pop[]=    { 0xd0 };
  2937. Xstatic unsigned char push[]=    { 0xc0 };
  2938. Xstatic unsigned char ret[]=    { 0x22 };
  2939. Xstatic unsigned char reti[]=    { 0x32 };
  2940. Xstatic unsigned char rl[]=    { 0x23 };
  2941. Xstatic unsigned char rlc[]=    { 0x33 };
  2942. Xstatic unsigned char rr[]=    { 0x03 };
  2943. Xstatic unsigned char rrc[]=    { 0x13 };
  2944. Xstatic unsigned char setb[]=    { 0xd3, 0xd2 };
  2945. Xstatic unsigned char sjmp[]=    { 0x80 };
  2946. Xstatic unsigned char subb[]=    { 0x98, 0x95, 0x96, 0x94 };
  2947. Xstatic unsigned char swap[]=    { 0xc4 };
  2948. Xstatic unsigned char xch[]=    { 0xc8, 0xc5, 0xc6 };
  2949. Xstatic unsigned char xchd[]=    { 0xd6 };
  2950. Xstatic unsigned char xrl[]=    { 0x68, 0x65, 0x66, 0x64, 0x62, 0x63 };
  2951. X
  2952. X/* ----------------------------------------------------------------------
  2953. X * optable[]
  2954. X *    This table contains opcodes, directives and a few reserved
  2955. X *    symbols.
  2956. X *
  2957. X *    The second field is the keywords token value.
  2958. X *
  2959. X *    Unless the symbol is an opcode, the third field will
  2960. X *    be NULL.
  2961. X * 
  2962. X *    The third field is a pointer to an array of opcode bytes.
  2963. X *
  2964. X */
  2965. X
  2966. Xstatic struct opcode optable[] = {
  2967. X    {"a",        A,    NULL        },
  2968. X    {"ab",        AB,    NULL        },
  2969. X    {"acall",    ACALL,    acall        },
  2970. X    {"add",        ADD,    add        },
  2971. X    {"addc",    ADDC,    addc        },
  2972. X    {"ajmp",    AJMP,    ajmp        },
  2973. X    {"anl",        ANL,    anl        },
  2974. X    {"byte",    D_BYTE,    NULL        },
  2975. X    {"c",        C,    NULL        },
  2976. X    {"cjne",    CJNE,    cjne        },
  2977. X    {"clr",        CLR,    clr        },
  2978. X    {"cpl",        CPL,    cpl        },
  2979. X    {"da",        DA,    da        },
  2980. X    {"dec",        DEC,    dec        },
  2981. X    {"div",        DIV,    div        },
  2982. X    {"djnz",    DJNZ,    djnz        },
  2983. X    {"dptr",    DPTR,    NULL        },
  2984. X    {"end",        D_END,    NULL        },
  2985. X    {"equ",        D_EQU,    NULL        },
  2986. X    {"flag",    D_FLAG,    NULL        },
  2987. X    {"inc",        INC,    inc        },
  2988. X    {"jb",        JB,    jb        },
  2989. X    {"jbc",        JBC,    jbc        },
  2990. X    {"jc",        JC,    jc        },
  2991. X    {"jmp",        JMP,    jmp        },
  2992. X    {"jnb",        JNB,    jnb        },
  2993. X    {"jnc",        JNC,    jnc        },
  2994. X    {"jnz",        JNZ,    jnz        },
  2995. X    {"jz",        JZ,    jz        },
  2996. X    {"lcall",    LCALL,    lcall        },
  2997. X    {"ljmp",    LJMP,    ljmp        },
  2998. X    {"mov",        MOV,    mov        },
  2999. X    {"movc",    MOVC,    movc        },
  3000. X    {"movx",    MOVX,    movx        },
  3001. X    {"mul",        MUL,    mul        },
  3002. X    {"nop",        NOP,    nop        },
  3003. X    {"org",        D_ORG,    NULL        },
  3004. X    {"orl",        ORL,    orl        },
  3005. X    {"pc",        PC,    NULL        },
  3006. X    {"pop",        POP,    pop        },
  3007. X    {"push",    PUSH,    push        },
  3008. X    {"r0",        R0,    NULL        },
  3009. X    {"r1",        R1,    NULL        },
  3010. X    {"r2",        R2,    NULL        },
  3011. X    {"r3",        R3,    NULL        },
  3012. X    {"r4",        R4,    NULL        },
  3013. X    {"r5",        R5,    NULL        },
  3014. X    {"r6",        R6,    NULL        },
  3015. X    {"r7",        R7,    NULL        },
  3016. X    {"ret",        RET,    ret        },
  3017. X    {"reti",    RETI,    reti        },
  3018. X    {"rl",        RL,    rl        },
  3019. X    {"rlc",        RLC,    rlc        },
  3020. X    {"rr",        RR,    rr        },
  3021. X    {"rrc",        RRC,    rrc        },
  3022. X    {"setb",    SETB,    setb        },
  3023. X    {"sjmp",    SJMP,    sjmp        },
  3024. X    {"skip",    D_SKIP,    NULL        },
  3025. X    {"subb",    SUBB,    subb        },
  3026. X    {"swap",    SWAP,    swap        },
  3027. X    {"word",    D_WORD,    NULL        },
  3028. X    {"xch",        XCH,    xch        },
  3029. X    {"xchd",    XCHD,    xchd        },
  3030. X    {"xrl",        XRL,    xrl        }
  3031. X};
  3032. X
  3033. X#define OPTABSIZE    (sizeof(optable)/sizeof(struct opcode))
  3034. X
  3035. X/* ----------------------------------------------------------------------
  3036. X * strcase:
  3037. X *    A case IN-sensitive string compare.
  3038. X *
  3039. X */
  3040. X
  3041. Xstrcase(s,t)
  3042. Xchar *s,*t;
  3043. X{
  3044. X    for( ; (*s|040) == (*t|040); s++, t++)
  3045. X        if( *s == '\0') return(0);
  3046. X    return( (*s|040) - (*t|040) );
  3047. X}
  3048. X
  3049. X/* ----------------------------------------------------------------------
  3050. X * lookop:
  3051. X *    Do a binary search through optable[], for a matching
  3052. X *    symbol. Return the symbol found or NULL.
  3053. X *
  3054. X */
  3055. X
  3056. Xstruct opcode *lookop(s)
  3057. Xchar *s;
  3058. X{
  3059. X    register int low,high,mid,cond;
  3060. X
  3061. X    low = 0;
  3062. X    high = OPTABSIZE-1;
  3063. X    while( low<=high ) {
  3064. X        mid = (low+high)/2;
  3065. X        if( (cond = strcase(s,optable[mid].name)) < 0 )
  3066. X            high = mid-1;
  3067. X        else if(cond > 0 )
  3068. X            low = mid+1;
  3069. X        else
  3070. X            return(&optable[mid]);
  3071. X    }
  3072. X    return(NULL);
  3073. X}
  3074. X
  3075. X/* ----------------------------------------------------------------------
  3076. X * symtab, hash, looksym:
  3077. X *    User symbol table routines.
  3078. X *    symtab is the hash table for the user symbols.
  3079. X *    (chaining is used for collision resolution).
  3080. X *
  3081. X */
  3082. X
  3083. Xstatic struct symbol *symtab[HASHTABSIZE];
  3084. X
  3085. Xstatic hash(s)
  3086. Xchar *s;
  3087. X{
  3088. X    register char *p;
  3089. X    register unsigned h=0,g;
  3090. X    for(p=s; *p; p++) {
  3091. X        h = (h<<4) + *p;
  3092. X        if( g = h&0xf0000000 ) {
  3093. X            h = h ^ (g >> 24);
  3094. X            h = h ^ g;
  3095. X        }
  3096. X    }
  3097. X    return( h % HASHTABSIZE );
  3098. X}
  3099. X
  3100. Xstruct symbol *looksym(s)
  3101. Xchar *s;
  3102. X{
  3103. X    register struct symbol *ptr,*prev;
  3104. X    char *malloc(),*p;
  3105. X    register int hv;
  3106. X
  3107. X    hv = hash(s);
  3108. X
  3109. X    prev = NULL;
  3110. X    for(ptr=symtab[hv]; ptr; ptr = ptr->next) {
  3111. X        if( !strcmp(ptr->name,s) ) {
  3112. X            if( prev != NULL ) {
  3113. X                prev->next = ptr->next;
  3114. X                ptr->next = symtab[hv];
  3115. X                symtab[hv] = ptr;
  3116. X            }
  3117. X            return(ptr);
  3118. X        }
  3119. X        prev = ptr;
  3120. X    }
  3121. X
  3122. X    if( p = malloc(strlen(s)+1) )
  3123. X        strcpy(p,s);
  3124. X    else
  3125. X        error("Cannot allocate %d bytes",strlen(s)+1);
  3126. X
  3127. X    ptr = (struct symbol *) malloc( sizeof(struct symbol) );
  3128. X    if( ptr == NULL )
  3129. X        error("Cannot allocate %d bytes",sizeof(struct symbol));
  3130. X    ptr->name = p;
  3131. X    ptr->type = UNDEF;
  3132. X    ptr->next = symtab[hv];
  3133. X    symtab[hv] = ptr;
  3134. X    return(ptr);
  3135. X}
  3136. X
  3137. X/* ----------------------------------------------------------------------
  3138. X * syminit:
  3139. X *    Initializes the hash table, with the initial symbols from
  3140. X *    sinit[]
  3141. X *
  3142. X */
  3143. X
  3144. Xsyminit()
  3145. X{
  3146. X    register int i,hv;
  3147. X
  3148. X    for(i=0; i<SINITSIZE; i++ ) {
  3149. X        hv = hash(sinit[i].name);
  3150. X        if( symtab[hv] )
  3151. X            sinit[i].next = symtab[hv];
  3152. X        symtab[hv] = &sinit[i];
  3153. X    }
  3154. X}
  3155. END_OF_FILE
  3156. if test 10609 -ne `wc -c <'symbol.c'`; then
  3157.     echo shar: \"'symbol.c'\" unpacked with wrong size!
  3158. fi
  3159. # end of 'symbol.c'
  3160. fi
  3161. if test -f 'new.asm' -a "${1}" != "-c" ; then 
  3162.   echo shar: Will not clobber existing file \"'new.asm'\"
  3163. else
  3164. echo shar: Extracting \"'new.asm'\" \(10618 characters\)
  3165. sed "s/^X//" >'new.asm' <<'END_OF_FILE'
  3166. X; -----------------------------------------------------------------------
  3167. X; -        debugger v2.0 theo de raadt 21/1/90            -
  3168. X; NOTE: Hardware has to be specially built to handle this monitor.
  3169. X; The CODE address space and the DATA address space have to be mapped
  3170. X; on top of each other. ie. CHIP_READ* = 8031RD* AND 8031PSEN* and
  3171. X; CHIP_WRITE* = 8031WR*.
  3172. X; Within this (combined) address space, you can now use either MOVX
  3173. X; or MOVC for the same effect.
  3174. X; In this address space, I have placed the rom this debugger is in
  3175. X; at 0x0000 and ram at 0x8000. (additional IO would go in between.)
  3176. X; (actually, I used a battery backed up static ram at 0x000.)
  3177. X; Some of the commands in the help are actually unimplimented. It
  3178. X; suited my purposes. The 'g' command could be much improved, to have
  3179. X; a seperate register set for the called routine.
  3180. X; -----------------------------------------------------------------------
  3181. X
  3182. X        .org    0
  3183. Xstart:        nop            ; for accidental overwrite if ram
  3184. X                    ; at 0 -- bug in my decode logic?
  3185. X        mov    P3, #0xff    ; use alternate fns on P3
  3186. X        ajmp    main
  3187. X
  3188. X; -----------------------------------------------------------------------
  3189. X; SERINIT() nothing hurt
  3190. Xserinit:    mov    TMOD, #0x20    ; timer 1 mode 2
  3191. X    ;    mov    TH1, #230    ; 1200 baud
  3192. X        mov    TH1,#243    ; 4800 baud
  3193. X        mov    TCON, #0x40    ; turn timer 1 on
  3194. X        mov    SCON, #0x52    ; serial mode 1 rx, fake tx done
  3195. X
  3196. X        mov    A, PCON        ; for 4800 baud
  3197. X        setb    ACC.7
  3198. X        mov    PCON, A
  3199. X        ret
  3200. X
  3201. X; -----------------------------------------------------------------------
  3202. X; PUTC( A=char )
  3203. Xputc:        jnb    TI, putc    ; wait for tx free
  3204. X        clr    TI
  3205. X        mov    SBUF, A        ; send it
  3206. X        ret
  3207. X
  3208. X; -----------------------------------------------------------------------
  3209. X; GETC() A=char
  3210. Xgetc:        jnb    RI, getc
  3211. X        clr    RI
  3212. X        mov    A, SBUF
  3213. X        ret
  3214. X
  3215. X; -----------------------------------------------------------------------
  3216. X; GETS( DPTR=start of string ) A not hurt, DPTR at start of string
  3217. Xgets:        push    ACC
  3218. X        push    DPL
  3219. X        push    DPH
  3220. X        mov    A, R3
  3221. X        push    ACC
  3222. X
  3223. X        clr    A
  3224. X        mov    R3, A
  3225. Xgets_nxt:    lcall    getc
  3226. X        cjne    A, #8, gets_notbs
  3227. X        ajmp    gets_bs
  3228. Xgets_notbs:    cjne    A, #'\r', gets_good
  3229. X        clr    A
  3230. X        movx    @DPTR, A
  3231. X
  3232. X        pop    ACC
  3233. X        mov    R3, A
  3234. X        pop    DPH
  3235. X        pop    DPL
  3236. X        pop    ACC
  3237. X        ret
  3238. X
  3239. Xgets_bs:    mov    A, R3        ; backspaced too far
  3240. X        jz    gets_nxt
  3241. X        dec    A
  3242. X        mov    R3, A
  3243. X
  3244. X        mov    A, #8        ; "\b \b"
  3245. X        lcall    putc
  3246. X        mov    A, #' '
  3247. X        lcall    putc
  3248. X        mov    A, #8
  3249. X        lcall    putc
  3250. X
  3251. X        setb    C        ; this is "dec DPTR"
  3252. X        mov    A, DPL
  3253. X        subb    A, #0
  3254. X        mov    DPL, A
  3255. X        mov    A, DPH
  3256. X        subb    A, #0
  3257. X        mov    DPH, A
  3258. X        ajmp    gets_nxt
  3259. X
  3260. Xgets_good:    movx    @DPTR, A
  3261. X        lcall    putc
  3262. X        inc    DPTR
  3263. X        inc    R3
  3264. X        ajmp    gets_nxt
  3265. X
  3266. X; ----------------------------------------------------------------------
  3267. X; HEXPARSE( DPTR=string ) A not hurt, DPTR advanced, R0/R1 [H/L] return
  3268. Xhexparse:    push    ACC
  3269. X
  3270. Xhp_char:    movx    A, @DPTR    ; get char
  3271. X
  3272. X        clr    C
  3273. X        subb    A, #'a'
  3274. X        jc    hp_notalpha    ; < 'a' not hex alpha char
  3275. X        subb    A, #5+1
  3276. X        jnc    hp_notalpha    ; > 'f' not hex aplha char
  3277. X        movx    A, @DPTR
  3278. X        clr    C
  3279. X        subb    A, #'a'-10
  3280. X        sjmp    hp_nybble
  3281. X
  3282. Xhp_notalpha:    movx    A, @DPTR
  3283. X        clr    C
  3284. X        subb    A, #'0'
  3285. X        jc    hp_notdigit    ; < '0' not hex digit
  3286. X        subb    A, #9+1
  3287. X        jnc    hp_notdigit    ; > '9' not hex digit
  3288. X        movx    A, @DPTR
  3289. X        clr    C
  3290. X        subb    A, #'0'
  3291. X
  3292. Xhp_nybble:    inc    DPTR
  3293. X
  3294. X        anl    A, #0x0f
  3295. X        push    ACC        ;     R0       R1
  3296. X        mov    A, R0        ;  HHHH LLLL hhhh llll
  3297. X        swap    A
  3298. X        anl    A, #0xf0
  3299. X        mov    R0, A
  3300. X        mov    A, R1
  3301. X        swap    A        ; shift left by nybble
  3302. X        anl    A, #0x0f
  3303. X        orl    A, R0
  3304. X        mov    R0, A
  3305. X        mov    A, R1
  3306. X        swap    A
  3307. X        anl    A, #0xf0
  3308. X        mov    R1, A
  3309. X        pop    ACC
  3310. X        orl    A, R1
  3311. X        mov    R1, A        ;  LLLL hhhh llll aaaa
  3312. X
  3313. X    ;    debugging
  3314. X    ;    push    ACC
  3315. X    ;    push    DPL
  3316. X    ;    push    DPH
  3317. X    ;    mov    DPH, R0
  3318. X    ;    mov    DPL, R1
  3319. X    ;    lcall    putword
  3320. X    ;    lcall    putnl
  3321. X    ;    pop    DPH
  3322. X    ;    pop    DPL
  3323. X    ;    pop    ACC
  3324. X
  3325. X        sjmp    hp_char
  3326. X
  3327. Xhp_notdigit:    pop    ACC
  3328. X        ret
  3329. X
  3330. X; ----------------------------------------------------------------------
  3331. X; EATSPACE( DPTR=string ) A not hurt, DPTR advanced
  3332. Xeatspace:    push    ACC
  3333. Xeatspace_loop:    movx    A, @DPTR
  3334. X        cjne    A, #' ', eatspace_done
  3335. X        inc    DPTR
  3336. X        sjmp    eatspace_loop
  3337. Xeatspace_done:    pop    ACC
  3338. X        ret
  3339. X
  3340. X; -----------------------------------------------------------------------
  3341. X; PUTS( DPTR=string ) A not hurt, DPTR at end of string
  3342. Xputs:        push    ACC
  3343. Xputs_ch:    movx    A, @DPTR    ; get ch
  3344. X        jz    puts_q        ; null - finished str
  3345. X        lcall    putc
  3346. X        inc    DPTR
  3347. X        sjmp    puts_ch        ; go for next
  3348. Xputs_q:        pop    ACC
  3349. X        ret
  3350. X
  3351. X; -----------------------------------------------------------------------
  3352. X; PUTNL() nothing hurt
  3353. Xputnl:        push    ACC
  3354. X        mov    A, #0x0d
  3355. X        lcall    putc
  3356. X        mov    A, #0x0a
  3357. X        lcall    putc
  3358. X        pop    ACC
  3359. X        ret
  3360. X
  3361. X; -----------------------------------------------------------------------
  3362. X; putword( DPTR=word) nothing hurt
  3363. Xputword:    push    ACC
  3364. X        mov    A, DPH
  3365. X        lcall    putbyte
  3366. X        mov    A, DPL
  3367. X        lcall    putbyte
  3368. X        pop    ACC
  3369. X        ret
  3370. X
  3371. X; -----------------------------------------------------------------------
  3372. X; putbyte( A=byte) nothing hurt
  3373. Xputbyte:    push    ACC
  3374. X        push    ACC
  3375. X        swap    A
  3376. X        lcall    putnyb
  3377. X        pop    ACC
  3378. X        lcall    putnyb
  3379. X        pop    ACC
  3380. X        ret
  3381. X
  3382. X; -----------------------------------------------------------------------
  3383. X; putnyb( A=nybble ) A hurt
  3384. Xputnyb:        anl    A, #0x0f
  3385. X        push    ACC
  3386. X        clr    C
  3387. X        subb    A, #10
  3388. X        jc    pn_digit    ; <= 9, then it's a digit
  3389. X        add    A, #'a'        ; alphabetic
  3390. X        lcall    putc
  3391. X        pop    ACC
  3392. X        ret
  3393. X
  3394. Xpn_digit:    pop    ACC        ; it's a digit
  3395. X        add    A, #'0'
  3396. X        lcall    putc
  3397. X        ret
  3398. X
  3399. X; -----------------------------------------------------------------------
  3400. Xmain:        lcall    serinit
  3401. X        mov    DPTR, #run_regs_psw    ; initialize psw at least!
  3402. X        clr    A
  3403. X        movx    @DPTR, A
  3404. X        mov    DPTR, #title_msg
  3405. X        lcall    puts
  3406. X
  3407. Xnext_line:    mov    A, #'>'        ; prompt
  3408. X        lcall    putc
  3409. X
  3410. X        mov    DPTR, #linebuf    ; get cmd
  3411. X        lcall    gets
  3412. X        lcall    putnl
  3413. X
  3414. Xnext_cmd:    lcall    eatspace
  3415. X        movx    A, @DPTR
  3416. X        jz    next_line
  3417. X
  3418. X        ; --------------------------------------------------
  3419. X        cjne    A, #'g', cmd_notgo    ; g --> lcall addr..
  3420. X        push    DPL
  3421. X        push    DPH
  3422. X        push    ACC
  3423. X        push    PSW
  3424. X
  3425. X        mov    DPTR, #go_return    ; come back to here..
  3426. X        push    DPL
  3427. X        push    DPH
  3428. X
  3429. X        mov    A, R1            ; return on top of function
  3430. X        push    ACC
  3431. X        mov    A, R0
  3432. X        push    ACC
  3433. X        mov    DPTR, #run_regs
  3434. X        movx    A, @DPTR        ; DPH
  3435. X        push    ACC
  3436. X        inc    DPTR
  3437. X        movx    A, @DPTR        ; DPL
  3438. X        push    ACC
  3439. X        inc    DPTR
  3440. X        movx    A, @DPTR        ; PSW
  3441. X        push    ACC
  3442. X        inc    DPTR
  3443. X        movx    A, @DPTR        ; ACC
  3444. X        pop    PSW
  3445. X        pop    DPL
  3446. X        pop    DPH
  3447. X        ret                ; enter it
  3448. X
  3449. Xgo_return:    pop    PSW
  3450. X        pop    ACC
  3451. X        pop    DPH
  3452. X        pop    DPL
  3453. X        inc    DPTR
  3454. X        sjmp    next_cmd
  3455. X
  3456. X        ; --------------------------------------------------
  3457. Xcmd_notgo:    cjne    A, #'R', cmd_notregs
  3458. X        inc    DPTR
  3459. X        push    DPH
  3460. X        push    DPL
  3461. X        mov    DPTR, #regs_msg        ; "DPTR ACC PSW"
  3462. X        lcall    puts
  3463. X        mov    DPTR, #run_regs
  3464. X        movx    A, @DPTR
  3465. X        acall    putbyte            ;  xx
  3466. X        inc    DPTR
  3467. X        movx    A, @DPTR
  3468. X        acall    putbyte            ;    xx
  3469. X        mov    A, #' '
  3470. X        acall    putc
  3471. X        inc    DPTR
  3472. X        movx    A, @DPTR
  3473. X        acall    putbyte            ;       xx
  3474. X        inc    DPTR
  3475. X        mov    A, #' '
  3476. X        acall    putc
  3477. X        acall    putc
  3478. X        movx    A, @DPTR
  3479. X        acall    putbyte            ;           xx
  3480. X        acall    putnl
  3481. X        pop    DPL
  3482. X        pop    DPH
  3483. X        sjmp    next_cmd
  3484. X
  3485. X        ; --------------------------------------------------
  3486. Xcmd_notregs:    cjne    A, #':', cmd_notenter    ; : --> eat bytes..
  3487. X        inc    DPTR
  3488. X        mov    A, R2
  3489. X        push    ACC
  3490. X        mov    A, R3
  3491. X        push    ACC
  3492. X        mov    A, R0
  3493. X        mov    R2, A
  3494. X        mov    A, R1
  3495. X        mov    R3, A        ; R2/R3 = mem ptr
  3496. X
  3497. Xenter_next:    lcall    eatspace
  3498. X        movx    A, @DPTR
  3499. X        jz    enter_done
  3500. X
  3501. X        push    DPL
  3502. X        clr    A
  3503. X        mov    R0, A
  3504. X        mov    R1, A
  3505. X        lcall    hexparse
  3506. X        pop    ACC
  3507. X        cjne    A, DPL, enter_number
  3508. X        sjmp    enter_next
  3509. X
  3510. Xenter_number:    push    DPL
  3511. X        push    DPH
  3512. X        mov    DPH, R2        ; put low byte only
  3513. X        mov    DPL, R3
  3514. X        mov    A, R1
  3515. X        movx    @DPTR, A
  3516. X        inc    DPTR
  3517. X        mov    R2, DPH
  3518. X        mov    R3, DPL
  3519. X        pop    DPH
  3520. X        pop    DPL
  3521. X        sjmp    enter_next
  3522. X
  3523. Xenter_done:    pop    ACC
  3524. X        mov    R3, A
  3525. X        pop    ACC
  3526. X        mov    R2, A
  3527. X        ajmp    next_cmd
  3528. X
  3529. X        ; --------------------------------------------------
  3530. Xcmd_notenter:    cjne    A, #'?', cmd_nothelp
  3531. X        push    DPL
  3532. X        push    DPH
  3533. X        mov    DPTR, #help_msg
  3534. X        lcall    puts
  3535. X        pop    DPH
  3536. X        pop    DPL
  3537. X        inc    DPTR
  3538. X        ajmp    next_cmd
  3539. X
  3540. X        ; --------------------------------------------------
  3541. Xcmd_nothelp:    cjne    A, #'l', cmd_notlist
  3542. X        push    DPL
  3543. X        push    DPH
  3544. X        push    B
  3545. X        clr    A
  3546. X        mov    B, ACC
  3547. X        mov    DPH, R0
  3548. X        mov    DPL, R1
  3549. X        lcall    putword        ; addr: [16 bytes]
  3550. X        mov    A, #':'
  3551. X        lcall    putc
  3552. X        mov    A, #' '
  3553. X        lcall    putc
  3554. Xcl_nextbyte:    movx    A, @DPTR
  3555. X        lcall    putbyte
  3556. X        mov    A, #' '
  3557. X        lcall    putc
  3558. X        inc    DPTR
  3559. X        inc    B
  3560. X        mov    A, B
  3561. X        cjne    A, #16, cl_nextbyte
  3562. X        lcall    putnl
  3563. X        mov    R0, DPH
  3564. X        mov    R1, DPL
  3565. X        pop    B
  3566. X        pop    DPH
  3567. X        pop    DPL
  3568. X        inc    DPTR
  3569. X        ajmp    next_cmd
  3570. X
  3571. X        ; --------------------------------------------------
  3572. Xcmd_notlist:    cjne    A, #'r', cmd_notread
  3573. X        mov    A, R3        ; counter
  3574. X        push    ACC
  3575. X        mov    A, R1        ; base addr
  3576. X        push    ACC
  3577. X
  3578. X        inc    DPTR        ; get arg
  3579. X        lcall    eatspace
  3580. X        push    DPL
  3581. X        lcall    hexparse
  3582. X        pop    ACC
  3583. X        cjne    A, DPL, nl_loop
  3584. X        mov    A, #1
  3585. X        mov    R3, A
  3586. X        sjmp    nl_start
  3587. Xnl_loop:    mov    A, R1
  3588. X        mov    R3, A
  3589. X        
  3590. Xnl_start:    pop    ACC
  3591. X        mov    R1, A
  3592. X        mov    A, R1        ; put address
  3593. X        lcall    putbyte
  3594. X        mov    A, #':'
  3595. X        lcall    putc
  3596. X
  3597. Xnl_nextloop:    mov    A, R3        ; eat one loop
  3598. X        jz    nl_endloop
  3599. X        dec    A
  3600. X        mov    R3, A
  3601. X
  3602. X        mov    A, #' '
  3603. X        lcall    putc
  3604. X        mov    A, @R1        ; put byte
  3605. X        lcall    putbyte
  3606. X        inc    R1        ; inc address
  3607. X
  3608. X        sjmp    nl_nextloop
  3609. X
  3610. Xnl_endloop:    lcall    putnl
  3611. X        pop    ACC
  3612. X        mov    R3, A
  3613. X        ajmp    next_cmd
  3614. X
  3615. X        ; --------------------------------------------------
  3616. Xcmd_notread:    cjne    A, #'w', cmd_notwrite
  3617. X        mov    A, R3
  3618. X        push    ACC
  3619. X        mov    A, R1
  3620. X        mov    R3, A        ; save addr
  3621. X        inc    DPTR
  3622. X
  3623. Xnr_nextbyte:    lcall    eatspace
  3624. X        movx    A, @DPTR
  3625. X        jz    nr_earlyeol    ; [addr] w [EOL]
  3626. X        push    DPL
  3627. X        lcall    hexparse    ; [addr] w [NONHEX]
  3628. X        pop    ACC
  3629. X        cjne    A, DPL, nr_good
  3630. X        sjmp    nr_earlyeol
  3631. X
  3632. Xnr_good:    mov    A, R3        ; R1 = value, R3 = addr
  3633. X        mov    R0, A
  3634. X        mov    A, R1
  3635. X        mov    @R0, A
  3636. X        ajmp    nr_nextbyte
  3637. X
  3638. Xnr_earlyeol:    pop    ACC
  3639. X        mov    R3, A
  3640. X        ajmp    next_cmd
  3641. X
  3642. X        ; --------------------------------------------------
  3643. Xcmd_notwrite:    cjne    A, #';', cmd_notcomment
  3644. X        ajmp    next_line
  3645. X
  3646. Xcmd_notcomment:    push    DPL
  3647. X        clr    A
  3648. X        mov    R0, A
  3649. X        mov    R1, A
  3650. X        lcall    hexparse        ; probably addr, see if ptr
  3651. X        pop    ACC            ; moved, else error
  3652. X        cjne    A, DPL, cmd_more
  3653. X        sjmp    cmd_error
  3654. X
  3655. X        ; --------------------------------------------------
  3656. Xcmd_more:
  3657. X    ;    debugging
  3658. X    ;    push    DPL
  3659. X    ;    push    DPH
  3660. X    ;    mov    DPTR, #number_msg
  3661. X    ;    lcall    puts
  3662. X    ;    mov    DPH, R0
  3663. X    ;    mov    DPL, R1
  3664. X    ;    lcall    putword
  3665. X    ;    lcall    putnl
  3666. X    ;    pop    DPH
  3667. X    ;    pop    DPL
  3668. X        ajmp    next_cmd
  3669. X
  3670. Xcmd_error:    mov    DPTR, #error_msg
  3671. X        lcall    puts
  3672. X        ajmp    next_line
  3673. X
  3674. X; -----------------------------------------------------------------------
  3675. Xtitle_msg:    .byte    "\r\n8031 mon v3.0\r\n", 0
  3676. Xerror_msg:    .byte    "syntax error\r\n", 0
  3677. Xregs_msg:    .byte    "DPTR ACC PSW\r\n", 0
  3678. Xhelp_msg:    .byte    "8031 mon v3.0\r\n"
  3679. X        .byte    "[addr] : [bytes]\tstore bytes\t"
  3680. X        .byte    "[addr] g\t\tcall address\r\n"
  3681. X        .byte    "[addr] l\t\tlist memory\t"
  3682. X        .byte    "[addr] r [count]\tlist onchip\r\n"
  3683. X        .byte    "[addr] w [bytes]\tstore onchip\t"
  3684. X        .byte    "; [comment]\t\tcomment\r\n"
  3685. X        .byte    "[value] D\t\tstore in DPTR\t"
  3686. X        .byte    "[value] A\t\tstore in ACC\r\n"
  3687. X        .byte    "[value] P\t\tstore in PSW\t"
  3688. X        .byte    "R\t\t\tprint registers\r\n", 0
  3689. X
  3690. X; -----------------------------------------------------------------------
  3691. X; sort of a bss segment
  3692. X; -----------------------------------------------------------------------
  3693. X        .org    0x8000
  3694. Xrun_regs:    .skip    2        ; DPTR [H/L]
  3695. Xrun_regs_psw:    .skip    1        ; PSW
  3696. X        .skip    1        ; ACC
  3697. Xlinebuf:    .skip    256
  3698. X
  3699. X        .end
  3700. END_OF_FILE
  3701. if test 10618 -ne `wc -c <'new.asm'`; then
  3702.     echo shar: \"'new.asm'\" unpacked with wrong size!
  3703. fi
  3704. # end of 'new.asm'
  3705. fi
  3706. echo shar: End of shell archive.
  3707. exit 0
  3708.  
  3709.